Merge branch 'ab/report-corrupt-object-with-type'
[git/jnareb-git/bp-gitweb.git] / t / t7800-difftool.sh
blob196827e7eacf0584379630f528fb7a4400f2b865
1 #!/bin/sh
3 # Copyright (c) 2009, 2010 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 skip_all='skipping difftool tests, perl not available'
15 test_done
18 LF='
21 remove_config_vars()
23 # Unset all config variables used by git-difftool
24 git config --unset diff.tool
25 git config --unset diff.guitool
26 git config --unset difftool.test-tool.cmd
27 git config --unset difftool.prompt
28 git config --unset merge.tool
29 git config --unset mergetool.test-tool.cmd
30 git config --unset mergetool.prompt
31 return 0
34 restore_test_defaults()
36 # Restores the test defaults used by several tests
37 remove_config_vars
38 unset GIT_DIFF_TOOL
39 unset GIT_DIFFTOOL_PROMPT
40 unset GIT_DIFFTOOL_NO_PROMPT
41 git config diff.tool test-tool &&
42 git config difftool.test-tool.cmd 'cat $LOCAL'
43 git config difftool.bogus-tool.cmd false
46 prompt_given()
48 prompt="$1"
49 test "$prompt" = "Hit return to launch 'test-tool': branch"
52 # Create a file on master and change it on branch
53 test_expect_success 'setup' '
54 echo master >file &&
55 git add file &&
56 git commit -m "added file" &&
58 git checkout -b branch master &&
59 echo branch >file &&
60 git commit -a -m "branch changed file" &&
61 git checkout master
64 # Configure a custom difftool.<tool>.cmd and use it
65 test_expect_success 'custom commands' '
66 restore_test_defaults &&
67 git config difftool.test-tool.cmd "cat \$REMOTE" &&
69 diff=$(git difftool --no-prompt branch) &&
70 test "$diff" = "master" &&
72 restore_test_defaults &&
73 diff=$(git difftool --no-prompt branch) &&
74 test "$diff" = "branch"
77 # Ensures that git-difftool ignores bogus --tool values
78 test_expect_success 'difftool ignores bad --tool values' '
79 diff=$(git difftool --no-prompt --tool=bad-tool branch)
80 test "$?" = 1 &&
81 test "$diff" = ""
84 test_expect_success 'difftool honors --gui' '
85 git config merge.tool bogus-tool &&
86 git config diff.tool bogus-tool &&
87 git config diff.guitool test-tool &&
89 diff=$(git difftool --no-prompt --gui branch) &&
90 test "$diff" = "branch" &&
92 restore_test_defaults
95 test_expect_success 'difftool --gui works without configured diff.guitool' '
96 git config diff.tool test-tool &&
98 diff=$(git difftool --no-prompt --gui branch) &&
99 test "$diff" = "branch" &&
101 restore_test_defaults
104 # Specify the diff tool using $GIT_DIFF_TOOL
105 test_expect_success 'GIT_DIFF_TOOL variable' '
106 git config --unset diff.tool
107 GIT_DIFF_TOOL=test-tool &&
108 export GIT_DIFF_TOOL &&
110 diff=$(git difftool --no-prompt branch) &&
111 test "$diff" = "branch" &&
113 restore_test_defaults
116 # Test the $GIT_*_TOOL variables and ensure
117 # that $GIT_DIFF_TOOL always wins unless --tool is specified
118 test_expect_success 'GIT_DIFF_TOOL overrides' '
119 git config diff.tool bogus-tool &&
120 git config merge.tool bogus-tool &&
122 GIT_DIFF_TOOL=test-tool &&
123 export GIT_DIFF_TOOL &&
125 diff=$(git difftool --no-prompt branch) &&
126 test "$diff" = "branch" &&
128 GIT_DIFF_TOOL=bogus-tool &&
129 export GIT_DIFF_TOOL &&
131 diff=$(git difftool --no-prompt --tool=test-tool branch) &&
132 test "$diff" = "branch" &&
134 restore_test_defaults
137 # Test that we don't have to pass --no-prompt to difftool
138 # when $GIT_DIFFTOOL_NO_PROMPT is true
139 test_expect_success 'GIT_DIFFTOOL_NO_PROMPT variable' '
140 GIT_DIFFTOOL_NO_PROMPT=true &&
141 export GIT_DIFFTOOL_NO_PROMPT &&
143 diff=$(git difftool branch) &&
144 test "$diff" = "branch" &&
146 restore_test_defaults
149 # git-difftool supports the difftool.prompt variable.
150 # Test that GIT_DIFFTOOL_PROMPT can override difftool.prompt = false
151 test_expect_success 'GIT_DIFFTOOL_PROMPT variable' '
152 git config difftool.prompt false &&
153 GIT_DIFFTOOL_PROMPT=true &&
154 export GIT_DIFFTOOL_PROMPT &&
156 prompt=$(echo | git difftool branch | tail -1) &&
157 prompt_given "$prompt" &&
159 restore_test_defaults
162 # Test that we don't have to pass --no-prompt when difftool.prompt is false
163 test_expect_success 'difftool.prompt config variable is false' '
164 git config difftool.prompt false &&
166 diff=$(git difftool branch) &&
167 test "$diff" = "branch" &&
169 restore_test_defaults
172 # Test that we don't have to pass --no-prompt when mergetool.prompt is false
173 test_expect_success 'difftool merge.prompt = false' '
174 git config --unset difftool.prompt
175 git config mergetool.prompt false &&
177 diff=$(git difftool branch) &&
178 test "$diff" = "branch" &&
180 restore_test_defaults
183 # Test that the -y flag can override difftool.prompt = true
184 test_expect_success 'difftool.prompt can overridden with -y' '
185 git config difftool.prompt true &&
187 diff=$(git difftool -y branch) &&
188 test "$diff" = "branch" &&
190 restore_test_defaults
193 # Test that the --prompt flag can override difftool.prompt = false
194 test_expect_success 'difftool.prompt can overridden with --prompt' '
195 git config difftool.prompt false &&
197 prompt=$(echo | git difftool --prompt branch | tail -1) &&
198 prompt_given "$prompt" &&
200 restore_test_defaults
203 # Test that the last flag passed on the command-line wins
204 test_expect_success 'difftool last flag wins' '
205 diff=$(git difftool --prompt --no-prompt branch) &&
206 test "$diff" = "branch" &&
208 restore_test_defaults &&
210 prompt=$(echo | git difftool --no-prompt --prompt branch | tail -1) &&
211 prompt_given "$prompt" &&
213 restore_test_defaults
216 # git-difftool falls back to git-mergetool config variables
217 # so test that behavior here
218 test_expect_success 'difftool + mergetool config variables' '
219 remove_config_vars
220 git config merge.tool test-tool &&
221 git config mergetool.test-tool.cmd "cat \$LOCAL" &&
223 diff=$(git difftool --no-prompt branch) &&
224 test "$diff" = "branch" &&
226 # set merge.tool to something bogus, diff.tool to test-tool
227 git config merge.tool bogus-tool &&
228 git config diff.tool test-tool &&
230 diff=$(git difftool --no-prompt branch) &&
231 test "$diff" = "branch" &&
233 restore_test_defaults
236 test_expect_success 'difftool.<tool>.path' '
237 git config difftool.tkdiff.path echo &&
238 diff=$(git difftool --tool=tkdiff --no-prompt branch) &&
239 git config --unset difftool.tkdiff.path &&
240 lines=$(echo "$diff" | grep file | wc -l) &&
241 test "$lines" -eq 1 &&
243 restore_test_defaults
246 test_expect_success 'difftool --extcmd=cat' '
247 diff=$(git difftool --no-prompt --extcmd=cat branch) &&
248 test "$diff" = branch"$LF"master
251 test_expect_success 'difftool --extcmd cat' '
252 diff=$(git difftool --no-prompt --extcmd cat branch) &&
253 test "$diff" = branch"$LF"master
256 test_expect_success 'difftool -x cat' '
257 diff=$(git difftool --no-prompt -x cat branch) &&
258 test "$diff" = branch"$LF"master
261 test_expect_success 'difftool --extcmd echo arg1' '
262 diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"echo\ \$1\" branch)
263 test "$diff" = file
266 test_expect_success 'difftool --extcmd cat arg1' '
267 diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"cat\ \$1\" branch)
268 test "$diff" = master
271 test_expect_success 'difftool --extcmd cat arg2' '
272 diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"cat\ \$2\" branch)
273 test "$diff" = branch
276 test_done