t7800-difftool: Set a bogus tool for use by tests
[git.git] / t / t7800-difftool.sh
blob707a0f54ae85a6095c57e2598bb5cd3fd83bceb3
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 difftool.test-tool.cmd
23 git config --unset difftool.prompt
24 git config --unset merge.tool
25 git config --unset mergetool.test-tool.cmd
26 return 0
29 restore_test_defaults()
31 # Restores the test defaults used by several tests
32 remove_config_vars
33 unset GIT_DIFF_TOOL
34 unset GIT_MERGE_TOOL
35 unset GIT_DIFFTOOL_PROMPT
36 unset GIT_DIFFTOOL_NO_PROMPT
37 git config diff.tool test-tool &&
38 git config difftool.test-tool.cmd 'cat $LOCAL'
39 git config difftool.bogus-tool.cmd false
42 prompt_given()
44 prompt="$1"
45 test "$prompt" = "Hit return to launch 'test-tool': branch"
48 # Create a file on master and change it on branch
49 test_expect_success 'setup' '
50 echo master >file &&
51 git add file &&
52 git commit -m "added file" &&
54 git checkout -b branch master &&
55 echo branch >file &&
56 git commit -a -m "branch changed file" &&
57 git checkout master
60 # Configure a custom difftool.<tool>.cmd and use it
61 test_expect_success 'custom commands' '
62 restore_test_defaults &&
63 git config difftool.test-tool.cmd "cat \$REMOTE" &&
65 diff=$(git difftool --no-prompt branch) &&
66 test "$diff" = "master" &&
68 restore_test_defaults &&
69 diff=$(git difftool --no-prompt branch) &&
70 test "$diff" = "branch"
73 # Ensures that git-difftool ignores bogus --tool values
74 test_expect_success 'difftool ignores bad --tool values' '
75 diff=$(git difftool --no-prompt --tool=bad-tool branch)
76 test "$?" = 1 &&
77 test "$diff" = ""
80 # Specify the diff tool using $GIT_DIFF_TOOL
81 test_expect_success 'GIT_DIFF_TOOL variable' '
82 git config --unset diff.tool
83 GIT_DIFF_TOOL=test-tool &&
84 export GIT_DIFF_TOOL &&
86 diff=$(git difftool --no-prompt branch) &&
87 test "$diff" = "branch" &&
89 restore_test_defaults
92 # Test the $GIT_*_TOOL variables and ensure
93 # that $GIT_DIFF_TOOL always wins unless --tool is specified
94 test_expect_success 'GIT_DIFF_TOOL overrides' '
95 git config diff.tool bogus-tool &&
96 git config merge.tool bogus-tool &&
98 GIT_MERGE_TOOL=test-tool &&
99 export GIT_MERGE_TOOL &&
100 diff=$(git difftool --no-prompt branch) &&
101 test "$diff" = "branch" &&
102 unset GIT_MERGE_TOOL &&
104 GIT_MERGE_TOOL=bogus-tool &&
105 GIT_DIFF_TOOL=test-tool &&
106 export GIT_MERGE_TOOL &&
107 export GIT_DIFF_TOOL &&
109 diff=$(git difftool --no-prompt branch) &&
110 test "$diff" = "branch" &&
112 GIT_DIFF_TOOL=bogus-tool &&
113 export GIT_DIFF_TOOL &&
115 diff=$(git difftool --no-prompt --tool=test-tool branch) &&
116 test "$diff" = "branch" &&
118 restore_test_defaults
121 # Test that we don't have to pass --no-prompt to difftool
122 # when $GIT_DIFFTOOL_NO_PROMPT is true
123 test_expect_success 'GIT_DIFFTOOL_NO_PROMPT variable' '
124 GIT_DIFFTOOL_NO_PROMPT=true &&
125 export GIT_DIFFTOOL_NO_PROMPT &&
127 diff=$(git difftool branch) &&
128 test "$diff" = "branch" &&
130 restore_test_defaults
133 # git-difftool supports the difftool.prompt variable.
134 # Test that GIT_DIFFTOOL_PROMPT can override difftool.prompt = false
135 test_expect_success 'GIT_DIFFTOOL_PROMPT variable' '
136 git config difftool.prompt false &&
137 GIT_DIFFTOOL_PROMPT=true &&
138 export GIT_DIFFTOOL_PROMPT &&
140 prompt=$(echo | git difftool branch | tail -1) &&
141 prompt_given "$prompt" &&
143 restore_test_defaults
146 # Test that we don't have to pass --no-prompt when difftool.prompt is false
147 test_expect_success 'difftool.prompt config variable is false' '
148 git config difftool.prompt false &&
150 diff=$(git difftool branch) &&
151 test "$diff" = "branch" &&
153 restore_test_defaults
156 # Test that the -y flag can override difftool.prompt = true
157 test_expect_success 'difftool.prompt can overridden with -y' '
158 git config difftool.prompt true &&
160 diff=$(git difftool -y branch) &&
161 test "$diff" = "branch" &&
163 restore_test_defaults
166 # Test that the --prompt flag can override difftool.prompt = false
167 test_expect_success 'difftool.prompt can overridden with --prompt' '
168 git config difftool.prompt false &&
170 prompt=$(echo | git difftool --prompt branch | tail -1) &&
171 prompt_given "$prompt" &&
173 restore_test_defaults
176 # Test that the last flag passed on the command-line wins
177 test_expect_success 'difftool last flag wins' '
178 diff=$(git difftool --prompt --no-prompt branch) &&
179 test "$diff" = "branch" &&
181 restore_test_defaults &&
183 prompt=$(echo | git difftool --no-prompt --prompt branch | tail -1) &&
184 prompt_given "$prompt" &&
186 restore_test_defaults
189 # git-difftool falls back to git-mergetool config variables
190 # so test that behavior here
191 test_expect_success 'difftool + mergetool config variables' '
192 remove_config_vars
193 git config merge.tool test-tool &&
194 git config mergetool.test-tool.cmd "cat \$LOCAL" &&
196 diff=$(git difftool --no-prompt branch) &&
197 test "$diff" = "branch" &&
199 # set merge.tool to something bogus, diff.tool to test-tool
200 git config merge.tool bogus-tool &&
201 git config diff.tool test-tool &&
203 diff=$(git difftool --no-prompt branch) &&
204 test "$diff" = "branch" &&
206 restore_test_defaults
209 test_expect_success 'difftool.<tool>.path' '
210 git config difftool.tkdiff.path echo &&
211 diff=$(git difftool --tool=tkdiff --no-prompt branch) &&
212 git config --unset difftool.tkdiff.path &&
213 lines=$(echo "$diff" | grep file | wc -l) &&
214 test "$lines" -eq 1
217 test_done