3 # Copyright (c) 2009, 2010 David Aguilar
6 test_description='git-difftool
8 Testing basic diff tool invocation
15 # Unset all config variables used by git-difftool
16 git config --unset diff.tool
17 git config --unset diff.guitool
18 git config --unset difftool.test-tool.cmd
19 git config --unset difftool.prompt
20 git config --unset merge.tool
21 git config --unset mergetool.test-tool.cmd
22 git config --unset mergetool.prompt
26 restore_test_defaults()
28 # Restores the test defaults used by several tests
31 unset GIT_DIFFTOOL_PROMPT
32 unset GIT_DIFFTOOL_NO_PROMPT
33 git config diff.tool test-tool &&
34 git config difftool.test-tool.cmd 'cat $LOCAL'
35 git config difftool.bogus-tool.cmd false
41 test "$prompt" = "Hit return to launch 'test-tool': branch"
44 # Create a file on master and change it on branch
45 test_expect_success PERL 'setup' '
48 git commit -m "added file" &&
50 git checkout -b branch master &&
52 git commit -a -m "branch changed file" &&
56 # Configure a custom difftool.<tool>.cmd and use it
57 test_expect_success PERL 'custom commands' '
58 restore_test_defaults &&
59 git config difftool.test-tool.cmd "cat \$REMOTE" &&
61 diff=$(git difftool --no-prompt branch) &&
62 test "$diff" = "master" &&
64 restore_test_defaults &&
65 diff=$(git difftool --no-prompt branch) &&
66 test "$diff" = "branch"
69 # Ensures that git-difftool ignores bogus --tool values
70 test_expect_success PERL 'difftool ignores bad --tool values' '
71 diff=$(git difftool --no-prompt --tool=bad-tool branch)
76 test_expect_success PERL 'difftool honors --gui' '
77 git config merge.tool bogus-tool &&
78 git config diff.tool bogus-tool &&
79 git config diff.guitool test-tool &&
81 diff=$(git difftool --no-prompt --gui branch) &&
82 test "$diff" = "branch" &&
87 test_expect_success PERL 'difftool --gui works without configured diff.guitool' '
88 git config diff.tool test-tool &&
90 diff=$(git difftool --no-prompt --gui branch) &&
91 test "$diff" = "branch" &&
96 # Specify the diff tool using $GIT_DIFF_TOOL
97 test_expect_success PERL 'GIT_DIFF_TOOL variable' '
98 test_might_fail git config --unset diff.tool &&
99 GIT_DIFF_TOOL=test-tool &&
100 export GIT_DIFF_TOOL &&
102 diff=$(git difftool --no-prompt branch) &&
103 test "$diff" = "branch" &&
105 restore_test_defaults
108 # Test the $GIT_*_TOOL variables and ensure
109 # that $GIT_DIFF_TOOL always wins unless --tool is specified
110 test_expect_success PERL 'GIT_DIFF_TOOL overrides' '
111 git config diff.tool bogus-tool &&
112 git config merge.tool bogus-tool &&
114 GIT_DIFF_TOOL=test-tool &&
115 export GIT_DIFF_TOOL &&
117 diff=$(git difftool --no-prompt branch) &&
118 test "$diff" = "branch" &&
120 GIT_DIFF_TOOL=bogus-tool &&
121 export GIT_DIFF_TOOL &&
123 diff=$(git difftool --no-prompt --tool=test-tool branch) &&
124 test "$diff" = "branch" &&
126 restore_test_defaults
129 # Test that we don't have to pass --no-prompt to difftool
130 # when $GIT_DIFFTOOL_NO_PROMPT is true
131 test_expect_success PERL 'GIT_DIFFTOOL_NO_PROMPT variable' '
132 GIT_DIFFTOOL_NO_PROMPT=true &&
133 export GIT_DIFFTOOL_NO_PROMPT &&
135 diff=$(git difftool branch) &&
136 test "$diff" = "branch" &&
138 restore_test_defaults
141 # git-difftool supports the difftool.prompt variable.
142 # Test that GIT_DIFFTOOL_PROMPT can override difftool.prompt = false
143 test_expect_success PERL 'GIT_DIFFTOOL_PROMPT variable' '
144 git config difftool.prompt false &&
145 GIT_DIFFTOOL_PROMPT=true &&
146 export GIT_DIFFTOOL_PROMPT &&
148 prompt=$(echo | git difftool branch | tail -1) &&
149 prompt_given "$prompt" &&
151 restore_test_defaults
154 # Test that we don't have to pass --no-prompt when difftool.prompt is false
155 test_expect_success PERL 'difftool.prompt config variable is false' '
156 git config difftool.prompt false &&
158 diff=$(git difftool branch) &&
159 test "$diff" = "branch" &&
161 restore_test_defaults
164 # Test that we don't have to pass --no-prompt when mergetool.prompt is false
165 test_expect_success PERL 'difftool merge.prompt = false' '
166 test_might_fail git config --unset difftool.prompt &&
167 git config mergetool.prompt false &&
169 diff=$(git difftool branch) &&
170 test "$diff" = "branch" &&
172 restore_test_defaults
175 # Test that the -y flag can override difftool.prompt = true
176 test_expect_success PERL 'difftool.prompt can overridden with -y' '
177 git config difftool.prompt true &&
179 diff=$(git difftool -y branch) &&
180 test "$diff" = "branch" &&
182 restore_test_defaults
185 # Test that the --prompt flag can override difftool.prompt = false
186 test_expect_success PERL 'difftool.prompt can overridden with --prompt' '
187 git config difftool.prompt false &&
189 prompt=$(echo | git difftool --prompt branch | tail -1) &&
190 prompt_given "$prompt" &&
192 restore_test_defaults
195 # Test that the last flag passed on the command-line wins
196 test_expect_success PERL 'difftool last flag wins' '
197 diff=$(git difftool --prompt --no-prompt branch) &&
198 test "$diff" = "branch" &&
200 restore_test_defaults &&
202 prompt=$(echo | git difftool --no-prompt --prompt branch | tail -1) &&
203 prompt_given "$prompt" &&
205 restore_test_defaults
208 # git-difftool falls back to git-mergetool config variables
209 # so test that behavior here
210 test_expect_success PERL 'difftool + mergetool config variables' '
211 remove_config_vars &&
212 git config merge.tool test-tool &&
213 git config mergetool.test-tool.cmd "cat \$LOCAL" &&
215 diff=$(git difftool --no-prompt branch) &&
216 test "$diff" = "branch" &&
218 # set merge.tool to something bogus, diff.tool to test-tool
219 git config merge.tool bogus-tool &&
220 git config diff.tool test-tool &&
222 diff=$(git difftool --no-prompt branch) &&
223 test "$diff" = "branch" &&
225 restore_test_defaults
228 test_expect_success PERL 'difftool.<tool>.path' '
229 git config difftool.tkdiff.path echo &&
230 diff=$(git difftool --tool=tkdiff --no-prompt branch) &&
231 git config --unset difftool.tkdiff.path &&
232 lines=$(echo "$diff" | grep file | wc -l) &&
233 test "$lines" -eq 1 &&
235 restore_test_defaults
238 test_expect_success PERL 'difftool --extcmd=cat' '
239 diff=$(git difftool --no-prompt --extcmd=cat branch) &&
240 test "$diff" = branch"$LF"master
243 test_expect_success PERL 'difftool --extcmd cat' '
244 diff=$(git difftool --no-prompt --extcmd cat branch) &&
245 test "$diff" = branch"$LF"master
248 test_expect_success PERL 'difftool -x cat' '
249 diff=$(git difftool --no-prompt -x cat branch) &&
250 test "$diff" = branch"$LF"master
253 test_expect_success PERL 'difftool --extcmd echo arg1' '
254 diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"echo\ \$1\" branch) &&
258 test_expect_success PERL 'difftool --extcmd cat arg1' '
259 diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"cat\ \$1\" branch) &&
260 test "$diff" = master
263 test_expect_success PERL 'difftool --extcmd cat arg2' '
264 diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"cat\ \$2\" branch) &&
265 test "$diff" = branch