difftool--helper: Remove use of the GIT_MERGE_TOOL variable
[git/dscho.git] / t / t7800-difftool.sh
blobeca51a8fe8090e22f49b3c983a95fe1388be4584
1 #!/bin/sh
3 # Copyright (c) 2009 David Aguilar
6 test_description='git-difftool
8 Testing basic diff tool invocation
11 . ./test-lib.sh
13 if ! test_have_prereq PERL; then
14 say 'skipping difftool tests, perl not available'
15 test_done
18 remove_config_vars()
20 # Unset all config variables used by git-difftool
21 git config --unset diff.tool
22 git config --unset diff.guitool
23 git config --unset difftool.test-tool.cmd
24 git config --unset difftool.prompt
25 git config --unset merge.tool
26 git config --unset mergetool.test-tool.cmd
27 return 0
30 restore_test_defaults()
32 # Restores the test defaults used by several tests
33 remove_config_vars
34 unset GIT_DIFF_TOOL
35 unset GIT_DIFFTOOL_PROMPT
36 unset GIT_DIFFTOOL_NO_PROMPT
37 git config diff.tool test-tool &&
38 git config difftool.test-tool.cmd 'cat $LOCAL'
39 git config difftool.bogus-tool.cmd false
42 prompt_given()
44 prompt="$1"
45 test "$prompt" = "Hit return to launch 'test-tool': branch"
48 # Create a file on master and change it on branch
49 test_expect_success 'setup' '
50 echo master >file &&
51 git add file &&
52 git commit -m "added file" &&
54 git checkout -b branch master &&
55 echo branch >file &&
56 git commit -a -m "branch changed file" &&
57 git checkout master
60 # Configure a custom difftool.<tool>.cmd and use it
61 test_expect_success 'custom commands' '
62 restore_test_defaults &&
63 git config difftool.test-tool.cmd "cat \$REMOTE" &&
65 diff=$(git difftool --no-prompt branch) &&
66 test "$diff" = "master" &&
68 restore_test_defaults &&
69 diff=$(git difftool --no-prompt branch) &&
70 test "$diff" = "branch"
73 # Ensures that git-difftool ignores bogus --tool values
74 test_expect_success 'difftool ignores bad --tool values' '
75 diff=$(git difftool --no-prompt --tool=bad-tool branch)
76 test "$?" = 1 &&
77 test "$diff" = ""
80 test_expect_success 'difftool honors --gui' '
81 git config merge.tool bogus-tool &&
82 git config diff.tool bogus-tool &&
83 git config diff.guitool test-tool &&
85 diff=$(git difftool --no-prompt --gui branch) &&
86 test "$diff" = "branch" &&
88 restore_test_defaults
91 # Specify the diff tool using $GIT_DIFF_TOOL
92 test_expect_success 'GIT_DIFF_TOOL variable' '
93 git config --unset diff.tool
94 GIT_DIFF_TOOL=test-tool &&
95 export GIT_DIFF_TOOL &&
97 diff=$(git difftool --no-prompt branch) &&
98 test "$diff" = "branch" &&
100 restore_test_defaults
103 # Test the $GIT_*_TOOL variables and ensure
104 # that $GIT_DIFF_TOOL always wins unless --tool is specified
105 test_expect_success 'GIT_DIFF_TOOL overrides' '
106 git config diff.tool bogus-tool &&
107 git config merge.tool bogus-tool &&
109 GIT_DIFF_TOOL=test-tool &&
110 export GIT_DIFF_TOOL &&
112 diff=$(git difftool --no-prompt branch) &&
113 test "$diff" = "branch" &&
115 GIT_DIFF_TOOL=bogus-tool &&
116 export GIT_DIFF_TOOL &&
118 diff=$(git difftool --no-prompt --tool=test-tool branch) &&
119 test "$diff" = "branch" &&
121 restore_test_defaults
124 # Test that we don't have to pass --no-prompt to difftool
125 # when $GIT_DIFFTOOL_NO_PROMPT is true
126 test_expect_success 'GIT_DIFFTOOL_NO_PROMPT variable' '
127 GIT_DIFFTOOL_NO_PROMPT=true &&
128 export GIT_DIFFTOOL_NO_PROMPT &&
130 diff=$(git difftool branch) &&
131 test "$diff" = "branch" &&
133 restore_test_defaults
136 # git-difftool supports the difftool.prompt variable.
137 # Test that GIT_DIFFTOOL_PROMPT can override difftool.prompt = false
138 test_expect_success 'GIT_DIFFTOOL_PROMPT variable' '
139 git config difftool.prompt false &&
140 GIT_DIFFTOOL_PROMPT=true &&
141 export GIT_DIFFTOOL_PROMPT &&
143 prompt=$(echo | git difftool branch | tail -1) &&
144 prompt_given "$prompt" &&
146 restore_test_defaults
149 # Test that we don't have to pass --no-prompt when difftool.prompt is false
150 test_expect_success 'difftool.prompt config variable is false' '
151 git config difftool.prompt false &&
153 diff=$(git difftool branch) &&
154 test "$diff" = "branch" &&
156 restore_test_defaults
159 # Test that the -y flag can override difftool.prompt = true
160 test_expect_success 'difftool.prompt can overridden with -y' '
161 git config difftool.prompt true &&
163 diff=$(git difftool -y branch) &&
164 test "$diff" = "branch" &&
166 restore_test_defaults
169 # Test that the --prompt flag can override difftool.prompt = false
170 test_expect_success 'difftool.prompt can overridden with --prompt' '
171 git config difftool.prompt false &&
173 prompt=$(echo | git difftool --prompt branch | tail -1) &&
174 prompt_given "$prompt" &&
176 restore_test_defaults
179 # Test that the last flag passed on the command-line wins
180 test_expect_success 'difftool last flag wins' '
181 diff=$(git difftool --prompt --no-prompt branch) &&
182 test "$diff" = "branch" &&
184 restore_test_defaults &&
186 prompt=$(echo | git difftool --no-prompt --prompt branch | tail -1) &&
187 prompt_given "$prompt" &&
189 restore_test_defaults
192 # git-difftool falls back to git-mergetool config variables
193 # so test that behavior here
194 test_expect_success 'difftool + mergetool config variables' '
195 remove_config_vars
196 git config merge.tool test-tool &&
197 git config mergetool.test-tool.cmd "cat \$LOCAL" &&
199 diff=$(git difftool --no-prompt branch) &&
200 test "$diff" = "branch" &&
202 # set merge.tool to something bogus, diff.tool to test-tool
203 git config merge.tool bogus-tool &&
204 git config diff.tool test-tool &&
206 diff=$(git difftool --no-prompt branch) &&
207 test "$diff" = "branch" &&
209 restore_test_defaults
212 test_expect_success 'difftool.<tool>.path' '
213 git config difftool.tkdiff.path echo &&
214 diff=$(git difftool --tool=tkdiff --no-prompt branch) &&
215 git config --unset difftool.tkdiff.path &&
216 lines=$(echo "$diff" | grep file | wc -l) &&
217 test "$lines" -eq 1
220 test_done