]>
Commit | Line | Data |
---|---|---|
f92f2038 DA |
1 | #!/bin/sh |
2 | # | |
c8a5672e | 3 | # Copyright (c) 2009, 2010 David Aguilar |
f92f2038 DA |
4 | # |
5 | ||
6 | test_description='git-difftool | |
7 | ||
8 | Testing basic diff tool invocation | |
9 | ' | |
10 | ||
11 | . ./test-lib.sh | |
12 | ||
13 | remove_config_vars() | |
14 | { | |
15 | # Unset all config variables used by git-difftool | |
16 | git config --unset diff.tool | |
4cefa495 | 17 | git config --unset diff.guitool |
f92f2038 | 18 | git config --unset difftool.test-tool.cmd |
a904392e | 19 | git config --unset difftool.prompt |
f92f2038 DA |
20 | git config --unset merge.tool |
21 | git config --unset mergetool.test-tool.cmd | |
a88183f1 | 22 | git config --unset mergetool.prompt |
f92f2038 DA |
23 | return 0 |
24 | } | |
25 | ||
26 | restore_test_defaults() | |
27 | { | |
28 | # Restores the test defaults used by several tests | |
29 | remove_config_vars | |
30 | unset GIT_DIFF_TOOL | |
a904392e | 31 | unset GIT_DIFFTOOL_PROMPT |
f92f2038 DA |
32 | unset GIT_DIFFTOOL_NO_PROMPT |
33 | git config diff.tool test-tool && | |
34 | git config difftool.test-tool.cmd 'cat $LOCAL' | |
23218bbd | 35 | git config difftool.bogus-tool.cmd false |
f92f2038 DA |
36 | } |
37 | ||
a904392e DA |
38 | prompt_given() |
39 | { | |
40 | prompt="$1" | |
ba959de1 SC |
41 | test "$prompt" = "Launch 'test-tool' [Y/n]: branch" |
42 | } | |
43 | ||
44 | stdin_contains() | |
45 | { | |
46 | grep >/dev/null "$1" | |
47 | } | |
48 | ||
49 | stdin_doesnot_contain() | |
50 | { | |
51 | ! stdin_contains "$1" | |
a904392e DA |
52 | } |
53 | ||
f92f2038 | 54 | # Create a file on master and change it on branch |
2c4f3026 | 55 | test_expect_success PERL 'setup' ' |
f92f2038 DA |
56 | echo master >file && |
57 | git add file && | |
58 | git commit -m "added file" && | |
59 | ||
60 | git checkout -b branch master && | |
61 | echo branch >file && | |
62 | git commit -a -m "branch changed file" && | |
63 | git checkout master | |
64 | ' | |
65 | ||
66 | # Configure a custom difftool.<tool>.cmd and use it | |
2c4f3026 | 67 | test_expect_success PERL 'custom commands' ' |
f92f2038 DA |
68 | restore_test_defaults && |
69 | git config difftool.test-tool.cmd "cat \$REMOTE" && | |
70 | ||
71 | diff=$(git difftool --no-prompt branch) && | |
72 | test "$diff" = "master" && | |
73 | ||
74 | restore_test_defaults && | |
75 | diff=$(git difftool --no-prompt branch) && | |
76 | test "$diff" = "branch" | |
77 | ' | |
78 | ||
79 | # Ensures that git-difftool ignores bogus --tool values | |
2c4f3026 | 80 | test_expect_success PERL 'difftool ignores bad --tool values' ' |
23218bbd | 81 | diff=$(git difftool --no-prompt --tool=bad-tool branch) |
f92f2038 DA |
82 | test "$?" = 1 && |
83 | test "$diff" = "" | |
84 | ' | |
85 | ||
d50b2c73 DA |
86 | test_expect_success PERL 'difftool forwards arguments to diff' ' |
87 | >for-diff && | |
88 | git add for-diff && | |
89 | echo changes>for-diff && | |
90 | git add for-diff && | |
91 | diff=$(git difftool --cached --no-prompt -- for-diff) && | |
92 | test "$diff" = "" && | |
93 | git reset -- for-diff && | |
94 | rm for-diff | |
95 | ' | |
96 | ||
2c4f3026 | 97 | test_expect_success PERL 'difftool honors --gui' ' |
4cefa495 DA |
98 | git config merge.tool bogus-tool && |
99 | git config diff.tool bogus-tool && | |
100 | git config diff.guitool test-tool && | |
101 | ||
102 | diff=$(git difftool --no-prompt --gui branch) && | |
103 | test "$diff" = "branch" && | |
104 | ||
105 | restore_test_defaults | |
106 | ' | |
107 | ||
85089604 TH |
108 | test_expect_success PERL 'difftool --gui last setting wins' ' |
109 | git config diff.guitool bogus-tool && | |
110 | git difftool --no-prompt --gui --no-gui && | |
111 | ||
112 | git config merge.tool bogus-tool && | |
113 | git config diff.tool bogus-tool && | |
114 | git config diff.guitool test-tool && | |
115 | diff=$(git difftool --no-prompt --no-gui --gui branch) && | |
116 | test "$diff" = "branch" && | |
117 | ||
118 | restore_test_defaults | |
119 | ' | |
120 | ||
2c4f3026 | 121 | test_expect_success PERL 'difftool --gui works without configured diff.guitool' ' |
42accaec DA |
122 | git config diff.tool test-tool && |
123 | ||
124 | diff=$(git difftool --no-prompt --gui branch) && | |
125 | test "$diff" = "branch" && | |
126 | ||
127 | restore_test_defaults | |
128 | ' | |
129 | ||
f92f2038 | 130 | # Specify the diff tool using $GIT_DIFF_TOOL |
2c4f3026 | 131 | test_expect_success PERL 'GIT_DIFF_TOOL variable' ' |
bc0f35ca | 132 | test_might_fail git config --unset diff.tool && |
f92f2038 DA |
133 | GIT_DIFF_TOOL=test-tool && |
134 | export GIT_DIFF_TOOL && | |
135 | ||
136 | diff=$(git difftool --no-prompt branch) && | |
137 | test "$diff" = "branch" && | |
138 | ||
139 | restore_test_defaults | |
140 | ' | |
141 | ||
142 | # Test the $GIT_*_TOOL variables and ensure | |
143 | # that $GIT_DIFF_TOOL always wins unless --tool is specified | |
2c4f3026 | 144 | test_expect_success PERL 'GIT_DIFF_TOOL overrides' ' |
f92f2038 DA |
145 | git config diff.tool bogus-tool && |
146 | git config merge.tool bogus-tool && | |
147 | ||
f92f2038 | 148 | GIT_DIFF_TOOL=test-tool && |
f92f2038 DA |
149 | export GIT_DIFF_TOOL && |
150 | ||
151 | diff=$(git difftool --no-prompt branch) && | |
152 | test "$diff" = "branch" && | |
153 | ||
154 | GIT_DIFF_TOOL=bogus-tool && | |
155 | export GIT_DIFF_TOOL && | |
156 | ||
157 | diff=$(git difftool --no-prompt --tool=test-tool branch) && | |
158 | test "$diff" = "branch" && | |
159 | ||
160 | restore_test_defaults | |
161 | ' | |
162 | ||
163 | # Test that we don't have to pass --no-prompt to difftool | |
164 | # when $GIT_DIFFTOOL_NO_PROMPT is true | |
2c4f3026 | 165 | test_expect_success PERL 'GIT_DIFFTOOL_NO_PROMPT variable' ' |
f92f2038 DA |
166 | GIT_DIFFTOOL_NO_PROMPT=true && |
167 | export GIT_DIFFTOOL_NO_PROMPT && | |
168 | ||
169 | diff=$(git difftool branch) && | |
170 | test "$diff" = "branch" && | |
171 | ||
172 | restore_test_defaults | |
173 | ' | |
174 | ||
a904392e DA |
175 | # git-difftool supports the difftool.prompt variable. |
176 | # Test that GIT_DIFFTOOL_PROMPT can override difftool.prompt = false | |
2c4f3026 | 177 | test_expect_success PERL 'GIT_DIFFTOOL_PROMPT variable' ' |
a904392e DA |
178 | git config difftool.prompt false && |
179 | GIT_DIFFTOOL_PROMPT=true && | |
180 | export GIT_DIFFTOOL_PROMPT && | |
181 | ||
3319df6f | 182 | prompt=$(echo | git difftool branch | tail -1) && |
a904392e DA |
183 | prompt_given "$prompt" && |
184 | ||
185 | restore_test_defaults | |
186 | ' | |
187 | ||
188 | # Test that we don't have to pass --no-prompt when difftool.prompt is false | |
2c4f3026 | 189 | test_expect_success PERL 'difftool.prompt config variable is false' ' |
a904392e DA |
190 | git config difftool.prompt false && |
191 | ||
192 | diff=$(git difftool branch) && | |
193 | test "$diff" = "branch" && | |
194 | ||
195 | restore_test_defaults | |
196 | ' | |
197 | ||
a88183f1 | 198 | # Test that we don't have to pass --no-prompt when mergetool.prompt is false |
2c4f3026 | 199 | test_expect_success PERL 'difftool merge.prompt = false' ' |
bc0f35ca | 200 | test_might_fail git config --unset difftool.prompt && |
a88183f1 DA |
201 | git config mergetool.prompt false && |
202 | ||
203 | diff=$(git difftool branch) && | |
204 | test "$diff" = "branch" && | |
205 | ||
206 | restore_test_defaults | |
207 | ' | |
208 | ||
a904392e | 209 | # Test that the -y flag can override difftool.prompt = true |
2c4f3026 | 210 | test_expect_success PERL 'difftool.prompt can overridden with -y' ' |
a904392e DA |
211 | git config difftool.prompt true && |
212 | ||
213 | diff=$(git difftool -y branch) && | |
214 | test "$diff" = "branch" && | |
215 | ||
216 | restore_test_defaults | |
217 | ' | |
218 | ||
219 | # Test that the --prompt flag can override difftool.prompt = false | |
2c4f3026 | 220 | test_expect_success PERL 'difftool.prompt can overridden with --prompt' ' |
a904392e DA |
221 | git config difftool.prompt false && |
222 | ||
223 | prompt=$(echo | git difftool --prompt branch | tail -1) && | |
224 | prompt_given "$prompt" && | |
225 | ||
226 | restore_test_defaults | |
227 | ' | |
228 | ||
229 | # Test that the last flag passed on the command-line wins | |
2c4f3026 | 230 | test_expect_success PERL 'difftool last flag wins' ' |
a904392e DA |
231 | diff=$(git difftool --prompt --no-prompt branch) && |
232 | test "$diff" = "branch" && | |
233 | ||
234 | restore_test_defaults && | |
235 | ||
236 | prompt=$(echo | git difftool --no-prompt --prompt branch | tail -1) && | |
237 | prompt_given "$prompt" && | |
238 | ||
239 | restore_test_defaults | |
240 | ' | |
241 | ||
f92f2038 DA |
242 | # git-difftool falls back to git-mergetool config variables |
243 | # so test that behavior here | |
2c4f3026 | 244 | test_expect_success PERL 'difftool + mergetool config variables' ' |
bc0f35ca | 245 | remove_config_vars && |
f92f2038 DA |
246 | git config merge.tool test-tool && |
247 | git config mergetool.test-tool.cmd "cat \$LOCAL" && | |
248 | ||
249 | diff=$(git difftool --no-prompt branch) && | |
250 | test "$diff" = "branch" && | |
251 | ||
252 | # set merge.tool to something bogus, diff.tool to test-tool | |
253 | git config merge.tool bogus-tool && | |
254 | git config diff.tool test-tool && | |
255 | ||
256 | diff=$(git difftool --no-prompt branch) && | |
257 | test "$diff" = "branch" && | |
258 | ||
259 | restore_test_defaults | |
260 | ' | |
261 | ||
2c4f3026 | 262 | test_expect_success PERL 'difftool.<tool>.path' ' |
f92f2038 DA |
263 | git config difftool.tkdiff.path echo && |
264 | diff=$(git difftool --tool=tkdiff --no-prompt branch) && | |
265 | git config --unset difftool.tkdiff.path && | |
266 | lines=$(echo "$diff" | grep file | wc -l) && | |
1c6f5b52 DA |
267 | test "$lines" -eq 1 && |
268 | ||
269 | restore_test_defaults | |
270 | ' | |
271 | ||
2c4f3026 | 272 | test_expect_success PERL 'difftool --extcmd=cat' ' |
1c6f5b52 | 273 | diff=$(git difftool --no-prompt --extcmd=cat branch) && |
a9e11220 | 274 | test "$diff" = branch"$LF"master |
f47f1e2c | 275 | ' |
1c6f5b52 | 276 | |
2c4f3026 | 277 | test_expect_success PERL 'difftool --extcmd cat' ' |
f47f1e2c DA |
278 | diff=$(git difftool --no-prompt --extcmd cat branch) && |
279 | test "$diff" = branch"$LF"master | |
280 | ' | |
1c6f5b52 | 281 | |
2c4f3026 | 282 | test_expect_success PERL 'difftool -x cat' ' |
f47f1e2c DA |
283 | diff=$(git difftool --no-prompt -x cat branch) && |
284 | test "$diff" = branch"$LF"master | |
9f3d54d1 DA |
285 | ' |
286 | ||
2c4f3026 | 287 | test_expect_success PERL 'difftool --extcmd echo arg1' ' |
bc0f35ca | 288 | diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"echo\ \$1\" branch) && |
9f3d54d1 DA |
289 | test "$diff" = file |
290 | ' | |
1c6f5b52 | 291 | |
2c4f3026 | 292 | test_expect_success PERL 'difftool --extcmd cat arg1' ' |
bc0f35ca | 293 | diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"cat\ \$1\" branch) && |
9f3d54d1 DA |
294 | test "$diff" = master |
295 | ' | |
1c6f5b52 | 296 | |
2c4f3026 | 297 | test_expect_success PERL 'difftool --extcmd cat arg2' ' |
bc0f35ca | 298 | diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"cat\ \$2\" branch) && |
9f3d54d1 | 299 | test "$diff" = branch |
f92f2038 DA |
300 | ' |
301 | ||
ba959de1 SC |
302 | # Create a second file on master and a different version on branch |
303 | test_expect_success PERL 'setup with 2 files different' ' | |
304 | echo m2 >file2 && | |
305 | git add file2 && | |
306 | git commit -m "added file2" && | |
307 | ||
308 | git checkout branch && | |
309 | echo br2 >file2 && | |
310 | git add file2 && | |
311 | git commit -a -m "branch changed file2" && | |
312 | git checkout master | |
313 | ' | |
314 | ||
315 | test_expect_success PERL 'say no to the first file' ' | |
15a31e78 | 316 | diff=$( (echo n; echo) | git difftool -x cat branch ) && |
ba959de1 SC |
317 | |
318 | echo "$diff" | stdin_contains m2 && | |
319 | echo "$diff" | stdin_contains br2 && | |
320 | echo "$diff" | stdin_doesnot_contain master && | |
321 | echo "$diff" | stdin_doesnot_contain branch | |
322 | ' | |
323 | ||
324 | test_expect_success PERL 'say no to the second file' ' | |
15a31e78 | 325 | diff=$( (echo; echo n) | git difftool -x cat branch ) && |
ba959de1 SC |
326 | |
327 | echo "$diff" | stdin_contains master && | |
328 | echo "$diff" | stdin_contains branch && | |
329 | echo "$diff" | stdin_doesnot_contain m2 && | |
330 | echo "$diff" | stdin_doesnot_contain br2 | |
331 | ' | |
332 | ||
bf73fc21 TH |
333 | test_expect_success PERL 'difftool --tool-help' ' |
334 | tool_help=$(git difftool --tool-help) && | |
335 | echo "$tool_help" | stdin_contains tool | |
336 | ' | |
337 | ||
7e0abcec TH |
338 | test_expect_success PERL 'setup change in subdirectory' ' |
339 | git checkout master && | |
340 | mkdir sub && | |
341 | echo master >sub/sub && | |
342 | git add sub/sub && | |
343 | git commit -m "added sub/sub" && | |
344 | echo test >>file && | |
345 | echo test >>sub/sub && | |
346 | git add . && | |
347 | git commit -m "modified both" | |
348 | ' | |
349 | ||
350 | test_expect_success PERL 'difftool -d' ' | |
351 | diff=$(git difftool -d --extcmd ls branch) && | |
352 | echo "$diff" | stdin_contains sub && | |
353 | echo "$diff" | stdin_contains file | |
354 | ' | |
355 | ||
356 | test_expect_success PERL 'difftool --dir-diff' ' | |
357 | diff=$(git difftool --dir-diff --extcmd ls branch) && | |
358 | echo "$diff" | stdin_contains sub && | |
359 | echo "$diff" | stdin_contains file | |
360 | ' | |
361 | ||
362 | test_expect_success PERL 'difftool --dir-diff ignores --prompt' ' | |
363 | diff=$(git difftool --dir-diff --prompt --extcmd ls branch) && | |
364 | echo "$diff" | stdin_contains sub && | |
365 | echo "$diff" | stdin_contains file | |
366 | ' | |
367 | ||
368 | test_expect_success PERL 'difftool --dir-diff from subdirectory' ' | |
369 | ( | |
370 | cd sub && | |
371 | diff=$(git difftool --dir-diff --extcmd ls branch) && | |
372 | echo "$diff" | stdin_contains sub && | |
373 | echo "$diff" | stdin_contains file | |
374 | ) | |
375 | ' | |
376 | ||
f92f2038 | 377 | test_done |