git-difftool: Add '--gui' for selecting a GUI tool
[alt-git.git] / t / t7800-difftool.sh
blob9bf6c98c54f368dfc837a8c5c374021269f20707
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_MERGE_TOOL
36 unset GIT_DIFFTOOL_PROMPT
37 unset GIT_DIFFTOOL_NO_PROMPT
38 git config diff.tool test-tool &&
39 git config difftool.test-tool.cmd 'cat $LOCAL'
40 git config difftool.bogus-tool.cmd false
43 prompt_given()
45 prompt="$1"
46 test "$prompt" = "Hit return to launch 'test-tool': branch"
49 # Create a file on master and change it on branch
50 test_expect_success 'setup' '
51 echo master >file &&
52 git add file &&
53 git commit -m "added file" &&
55 git checkout -b branch master &&
56 echo branch >file &&
57 git commit -a -m "branch changed file" &&
58 git checkout master
61 # Configure a custom difftool.<tool>.cmd and use it
62 test_expect_success 'custom commands' '
63 restore_test_defaults &&
64 git config difftool.test-tool.cmd "cat \$REMOTE" &&
66 diff=$(git difftool --no-prompt branch) &&
67 test "$diff" = "master" &&
69 restore_test_defaults &&
70 diff=$(git difftool --no-prompt branch) &&
71 test "$diff" = "branch"
74 # Ensures that git-difftool ignores bogus --tool values
75 test_expect_success 'difftool ignores bad --tool values' '
76 diff=$(git difftool --no-prompt --tool=bad-tool branch)
77 test "$?" = 1 &&
78 test "$diff" = ""
81 test_expect_success 'difftool honors --gui' '
82 git config merge.tool bogus-tool &&
83 git config diff.tool bogus-tool &&
84 git config diff.guitool test-tool &&
86 diff=$(git difftool --no-prompt --gui branch) &&
87 test "$diff" = "branch" &&
89 restore_test_defaults
92 # Specify the diff tool using $GIT_DIFF_TOOL
93 test_expect_success 'GIT_DIFF_TOOL variable' '
94 git config --unset diff.tool
95 GIT_DIFF_TOOL=test-tool &&
96 export GIT_DIFF_TOOL &&
98 diff=$(git difftool --no-prompt branch) &&
99 test "$diff" = "branch" &&
101 restore_test_defaults
104 # Test the $GIT_*_TOOL variables and ensure
105 # that $GIT_DIFF_TOOL always wins unless --tool is specified
106 test_expect_success 'GIT_DIFF_TOOL overrides' '
107 git config diff.tool bogus-tool &&
108 git config merge.tool bogus-tool &&
110 GIT_MERGE_TOOL=test-tool &&
111 export GIT_MERGE_TOOL &&
112 diff=$(git difftool --no-prompt branch) &&
113 test "$diff" = "branch" &&
114 unset GIT_MERGE_TOOL &&
116 GIT_MERGE_TOOL=bogus-tool &&
117 GIT_DIFF_TOOL=test-tool &&
118 export GIT_MERGE_TOOL &&
119 export GIT_DIFF_TOOL &&
121 diff=$(git difftool --no-prompt branch) &&
122 test "$diff" = "branch" &&
124 GIT_DIFF_TOOL=bogus-tool &&
125 export GIT_DIFF_TOOL &&
127 diff=$(git difftool --no-prompt --tool=test-tool branch) &&
128 test "$diff" = "branch" &&
130 restore_test_defaults
133 # Test that we don't have to pass --no-prompt to difftool
134 # when $GIT_DIFFTOOL_NO_PROMPT is true
135 test_expect_success 'GIT_DIFFTOOL_NO_PROMPT variable' '
136 GIT_DIFFTOOL_NO_PROMPT=true &&
137 export GIT_DIFFTOOL_NO_PROMPT &&
139 diff=$(git difftool branch) &&
140 test "$diff" = "branch" &&
142 restore_test_defaults
145 # git-difftool supports the difftool.prompt variable.
146 # Test that GIT_DIFFTOOL_PROMPT can override difftool.prompt = false
147 test_expect_success 'GIT_DIFFTOOL_PROMPT variable' '
148 git config difftool.prompt false &&
149 GIT_DIFFTOOL_PROMPT=true &&
150 export GIT_DIFFTOOL_PROMPT &&
152 prompt=$(echo | git difftool branch | tail -1) &&
153 prompt_given "$prompt" &&
155 restore_test_defaults
158 # Test that we don't have to pass --no-prompt when difftool.prompt is false
159 test_expect_success 'difftool.prompt config variable is false' '
160 git config difftool.prompt false &&
162 diff=$(git difftool branch) &&
163 test "$diff" = "branch" &&
165 restore_test_defaults
168 # Test that the -y flag can override difftool.prompt = true
169 test_expect_success 'difftool.prompt can overridden with -y' '
170 git config difftool.prompt true &&
172 diff=$(git difftool -y branch) &&
173 test "$diff" = "branch" &&
175 restore_test_defaults
178 # Test that the --prompt flag can override difftool.prompt = false
179 test_expect_success 'difftool.prompt can overridden with --prompt' '
180 git config difftool.prompt false &&
182 prompt=$(echo | git difftool --prompt branch | tail -1) &&
183 prompt_given "$prompt" &&
185 restore_test_defaults
188 # Test that the last flag passed on the command-line wins
189 test_expect_success 'difftool last flag wins' '
190 diff=$(git difftool --prompt --no-prompt branch) &&
191 test "$diff" = "branch" &&
193 restore_test_defaults &&
195 prompt=$(echo | git difftool --no-prompt --prompt branch | tail -1) &&
196 prompt_given "$prompt" &&
198 restore_test_defaults
201 # git-difftool falls back to git-mergetool config variables
202 # so test that behavior here
203 test_expect_success 'difftool + mergetool config variables' '
204 remove_config_vars
205 git config merge.tool test-tool &&
206 git config mergetool.test-tool.cmd "cat \$LOCAL" &&
208 diff=$(git difftool --no-prompt branch) &&
209 test "$diff" = "branch" &&
211 # set merge.tool to something bogus, diff.tool to test-tool
212 git config merge.tool bogus-tool &&
213 git config diff.tool test-tool &&
215 diff=$(git difftool --no-prompt branch) &&
216 test "$diff" = "branch" &&
218 restore_test_defaults
221 test_expect_success 'difftool.<tool>.path' '
222 git config difftool.tkdiff.path echo &&
223 diff=$(git difftool --tool=tkdiff --no-prompt branch) &&
224 git config --unset difftool.tkdiff.path &&
225 lines=$(echo "$diff" | grep file | wc -l) &&
226 test "$lines" -eq 1
229 test_done