]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7800-difftool.sh
Git 1.7.7
[thirdparty/git.git] / t / t7800-difftool.sh
CommitLineData
f92f2038
DA
1#!/bin/sh
2#
c8a5672e 3# Copyright (c) 2009, 2010 David Aguilar
f92f2038
DA
4#
5
6test_description='git-difftool
7
8Testing basic diff tool invocation
9'
10
11. ./test-lib.sh
12
13remove_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
26restore_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
38prompt_given()
39{
40 prompt="$1"
41 test "$prompt" = "Hit return to launch 'test-tool': branch"
42}
43
f92f2038 44# Create a file on master and change it on branch
2c4f3026 45test_expect_success PERL 'setup' '
f92f2038
DA
46 echo master >file &&
47 git add file &&
48 git commit -m "added file" &&
49
50 git checkout -b branch master &&
51 echo branch >file &&
52 git commit -a -m "branch changed file" &&
53 git checkout master
54'
55
56# Configure a custom difftool.<tool>.cmd and use it
2c4f3026 57test_expect_success PERL 'custom commands' '
f92f2038
DA
58 restore_test_defaults &&
59 git config difftool.test-tool.cmd "cat \$REMOTE" &&
60
61 diff=$(git difftool --no-prompt branch) &&
62 test "$diff" = "master" &&
63
64 restore_test_defaults &&
65 diff=$(git difftool --no-prompt branch) &&
66 test "$diff" = "branch"
67'
68
69# Ensures that git-difftool ignores bogus --tool values
2c4f3026 70test_expect_success PERL 'difftool ignores bad --tool values' '
23218bbd 71 diff=$(git difftool --no-prompt --tool=bad-tool branch)
f92f2038
DA
72 test "$?" = 1 &&
73 test "$diff" = ""
74'
75
2c4f3026 76test_expect_success PERL 'difftool honors --gui' '
4cefa495
DA
77 git config merge.tool bogus-tool &&
78 git config diff.tool bogus-tool &&
79 git config diff.guitool test-tool &&
80
81 diff=$(git difftool --no-prompt --gui branch) &&
82 test "$diff" = "branch" &&
83
84 restore_test_defaults
85'
86
2c4f3026 87test_expect_success PERL 'difftool --gui works without configured diff.guitool' '
42accaec
DA
88 git config diff.tool test-tool &&
89
90 diff=$(git difftool --no-prompt --gui branch) &&
91 test "$diff" = "branch" &&
92
93 restore_test_defaults
94'
95
f92f2038 96# Specify the diff tool using $GIT_DIFF_TOOL
2c4f3026 97test_expect_success PERL 'GIT_DIFF_TOOL variable' '
bc0f35ca 98 test_might_fail git config --unset diff.tool &&
f92f2038
DA
99 GIT_DIFF_TOOL=test-tool &&
100 export GIT_DIFF_TOOL &&
101
102 diff=$(git difftool --no-prompt branch) &&
103 test "$diff" = "branch" &&
104
105 restore_test_defaults
106'
107
108# Test the $GIT_*_TOOL variables and ensure
109# that $GIT_DIFF_TOOL always wins unless --tool is specified
2c4f3026 110test_expect_success PERL 'GIT_DIFF_TOOL overrides' '
f92f2038
DA
111 git config diff.tool bogus-tool &&
112 git config merge.tool bogus-tool &&
113
f92f2038 114 GIT_DIFF_TOOL=test-tool &&
f92f2038
DA
115 export GIT_DIFF_TOOL &&
116
117 diff=$(git difftool --no-prompt branch) &&
118 test "$diff" = "branch" &&
119
120 GIT_DIFF_TOOL=bogus-tool &&
121 export GIT_DIFF_TOOL &&
122
123 diff=$(git difftool --no-prompt --tool=test-tool branch) &&
124 test "$diff" = "branch" &&
125
126 restore_test_defaults
127'
128
129# Test that we don't have to pass --no-prompt to difftool
130# when $GIT_DIFFTOOL_NO_PROMPT is true
2c4f3026 131test_expect_success PERL 'GIT_DIFFTOOL_NO_PROMPT variable' '
f92f2038
DA
132 GIT_DIFFTOOL_NO_PROMPT=true &&
133 export GIT_DIFFTOOL_NO_PROMPT &&
134
135 diff=$(git difftool branch) &&
136 test "$diff" = "branch" &&
137
138 restore_test_defaults
139'
140
a904392e
DA
141# git-difftool supports the difftool.prompt variable.
142# Test that GIT_DIFFTOOL_PROMPT can override difftool.prompt = false
2c4f3026 143test_expect_success PERL 'GIT_DIFFTOOL_PROMPT variable' '
a904392e
DA
144 git config difftool.prompt false &&
145 GIT_DIFFTOOL_PROMPT=true &&
146 export GIT_DIFFTOOL_PROMPT &&
147
3319df6f 148 prompt=$(echo | git difftool branch | tail -1) &&
a904392e
DA
149 prompt_given "$prompt" &&
150
151 restore_test_defaults
152'
153
154# Test that we don't have to pass --no-prompt when difftool.prompt is false
2c4f3026 155test_expect_success PERL 'difftool.prompt config variable is false' '
a904392e
DA
156 git config difftool.prompt false &&
157
158 diff=$(git difftool branch) &&
159 test "$diff" = "branch" &&
160
161 restore_test_defaults
162'
163
a88183f1 164# Test that we don't have to pass --no-prompt when mergetool.prompt is false
2c4f3026 165test_expect_success PERL 'difftool merge.prompt = false' '
bc0f35ca 166 test_might_fail git config --unset difftool.prompt &&
a88183f1
DA
167 git config mergetool.prompt false &&
168
169 diff=$(git difftool branch) &&
170 test "$diff" = "branch" &&
171
172 restore_test_defaults
173'
174
a904392e 175# Test that the -y flag can override difftool.prompt = true
2c4f3026 176test_expect_success PERL 'difftool.prompt can overridden with -y' '
a904392e
DA
177 git config difftool.prompt true &&
178
179 diff=$(git difftool -y branch) &&
180 test "$diff" = "branch" &&
181
182 restore_test_defaults
183'
184
185# Test that the --prompt flag can override difftool.prompt = false
2c4f3026 186test_expect_success PERL 'difftool.prompt can overridden with --prompt' '
a904392e
DA
187 git config difftool.prompt false &&
188
189 prompt=$(echo | git difftool --prompt branch | tail -1) &&
190 prompt_given "$prompt" &&
191
192 restore_test_defaults
193'
194
195# Test that the last flag passed on the command-line wins
2c4f3026 196test_expect_success PERL 'difftool last flag wins' '
a904392e
DA
197 diff=$(git difftool --prompt --no-prompt branch) &&
198 test "$diff" = "branch" &&
199
200 restore_test_defaults &&
201
202 prompt=$(echo | git difftool --no-prompt --prompt branch | tail -1) &&
203 prompt_given "$prompt" &&
204
205 restore_test_defaults
206'
207
f92f2038
DA
208# git-difftool falls back to git-mergetool config variables
209# so test that behavior here
2c4f3026 210test_expect_success PERL 'difftool + mergetool config variables' '
bc0f35ca 211 remove_config_vars &&
f92f2038
DA
212 git config merge.tool test-tool &&
213 git config mergetool.test-tool.cmd "cat \$LOCAL" &&
214
215 diff=$(git difftool --no-prompt branch) &&
216 test "$diff" = "branch" &&
217
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 &&
221
222 diff=$(git difftool --no-prompt branch) &&
223 test "$diff" = "branch" &&
224
225 restore_test_defaults
226'
227
2c4f3026 228test_expect_success PERL 'difftool.<tool>.path' '
f92f2038
DA
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) &&
1c6f5b52
DA
233 test "$lines" -eq 1 &&
234
235 restore_test_defaults
236'
237
2c4f3026 238test_expect_success PERL 'difftool --extcmd=cat' '
1c6f5b52 239 diff=$(git difftool --no-prompt --extcmd=cat branch) &&
a9e11220 240 test "$diff" = branch"$LF"master
f47f1e2c 241'
1c6f5b52 242
2c4f3026 243test_expect_success PERL 'difftool --extcmd cat' '
f47f1e2c
DA
244 diff=$(git difftool --no-prompt --extcmd cat branch) &&
245 test "$diff" = branch"$LF"master
246'
1c6f5b52 247
2c4f3026 248test_expect_success PERL 'difftool -x cat' '
f47f1e2c
DA
249 diff=$(git difftool --no-prompt -x cat branch) &&
250 test "$diff" = branch"$LF"master
9f3d54d1
DA
251'
252
2c4f3026 253test_expect_success PERL 'difftool --extcmd echo arg1' '
bc0f35ca 254 diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"echo\ \$1\" branch) &&
9f3d54d1
DA
255 test "$diff" = file
256'
1c6f5b52 257
2c4f3026 258test_expect_success PERL 'difftool --extcmd cat arg1' '
bc0f35ca 259 diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"cat\ \$1\" branch) &&
9f3d54d1
DA
260 test "$diff" = master
261'
1c6f5b52 262
2c4f3026 263test_expect_success PERL 'difftool --extcmd cat arg2' '
bc0f35ca 264 diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"cat\ \$2\" branch) &&
9f3d54d1 265 test "$diff" = branch
f92f2038
DA
266'
267
268test_done