remove logical typo in documentation of sample update hook
[git/spearce.git] / t / t7800-difftool.sh
blobebdccf9a1eb9f9bb4918fc5adee8bdb8fd682608
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'
41 prompt_given()
43 prompt="$1"
44 test "$prompt" = "Hit return to launch 'test-tool': branch"
47 # Create a file on master and change it on branch
48 test_expect_success 'setup' '
49 echo master >file &&
50 git add file &&
51 git commit -m "added file" &&
53 git checkout -b branch master &&
54 echo branch >file &&
55 git commit -a -m "branch changed file" &&
56 git checkout master
59 # Configure a custom difftool.<tool>.cmd and use it
60 test_expect_success 'custom commands' '
61 restore_test_defaults &&
62 git config difftool.test-tool.cmd "cat \$REMOTE" &&
64 diff=$(git difftool --no-prompt branch) &&
65 test "$diff" = "master" &&
67 restore_test_defaults &&
68 diff=$(git difftool --no-prompt branch) &&
69 test "$diff" = "branch"
72 # Ensures that git-difftool ignores bogus --tool values
73 test_expect_success 'difftool ignores bad --tool values' '
74 diff=$(git difftool --no-prompt --tool=bogus-tool branch)
75 test "$?" = 1 &&
76 test "$diff" = ""
79 # Specify the diff tool using $GIT_DIFF_TOOL
80 test_expect_success 'GIT_DIFF_TOOL variable' '
81 git config --unset diff.tool
82 GIT_DIFF_TOOL=test-tool &&
83 export GIT_DIFF_TOOL &&
85 diff=$(git difftool --no-prompt branch) &&
86 test "$diff" = "branch" &&
88 restore_test_defaults
91 # Test the $GIT_*_TOOL variables and ensure
92 # that $GIT_DIFF_TOOL always wins unless --tool is specified
93 test_expect_success 'GIT_DIFF_TOOL overrides' '
94 git config diff.tool bogus-tool &&
95 git config merge.tool bogus-tool &&
97 GIT_MERGE_TOOL=test-tool &&
98 export GIT_MERGE_TOOL &&
99 diff=$(git difftool --no-prompt branch) &&
100 test "$diff" = "branch" &&
101 unset GIT_MERGE_TOOL &&
103 GIT_MERGE_TOOL=bogus-tool &&
104 GIT_DIFF_TOOL=test-tool &&
105 export GIT_MERGE_TOOL &&
106 export GIT_DIFF_TOOL &&
108 diff=$(git difftool --no-prompt branch) &&
109 test "$diff" = "branch" &&
111 GIT_DIFF_TOOL=bogus-tool &&
112 export GIT_DIFF_TOOL &&
114 diff=$(git difftool --no-prompt --tool=test-tool branch) &&
115 test "$diff" = "branch" &&
117 restore_test_defaults
120 # Test that we don't have to pass --no-prompt to difftool
121 # when $GIT_DIFFTOOL_NO_PROMPT is true
122 test_expect_success 'GIT_DIFFTOOL_NO_PROMPT variable' '
123 GIT_DIFFTOOL_NO_PROMPT=true &&
124 export GIT_DIFFTOOL_NO_PROMPT &&
126 diff=$(git difftool branch) &&
127 test "$diff" = "branch" &&
129 restore_test_defaults
132 # git-difftool supports the difftool.prompt variable.
133 # Test that GIT_DIFFTOOL_PROMPT can override difftool.prompt = false
134 test_expect_success 'GIT_DIFFTOOL_PROMPT variable' '
135 git config difftool.prompt false &&
136 GIT_DIFFTOOL_PROMPT=true &&
137 export GIT_DIFFTOOL_PROMPT &&
139 prompt=$(echo | git difftool --prompt branch | tail -1) &&
140 prompt_given "$prompt" &&
142 restore_test_defaults
145 # Test that we don't have to pass --no-prompt when difftool.prompt is false
146 test_expect_success 'difftool.prompt config variable is false' '
147 git config difftool.prompt false &&
149 diff=$(git difftool branch) &&
150 test "$diff" = "branch" &&
152 restore_test_defaults
155 # Test that the -y flag can override difftool.prompt = true
156 test_expect_success 'difftool.prompt can overridden with -y' '
157 git config difftool.prompt true &&
159 diff=$(git difftool -y branch) &&
160 test "$diff" = "branch" &&
162 restore_test_defaults
165 # Test that the --prompt flag can override difftool.prompt = false
166 test_expect_success 'difftool.prompt can overridden with --prompt' '
167 git config difftool.prompt false &&
169 prompt=$(echo | git difftool --prompt branch | tail -1) &&
170 prompt_given "$prompt" &&
172 restore_test_defaults
175 # Test that the last flag passed on the command-line wins
176 test_expect_success 'difftool last flag wins' '
177 diff=$(git difftool --prompt --no-prompt branch) &&
178 test "$diff" = "branch" &&
180 restore_test_defaults &&
182 prompt=$(echo | git difftool --no-prompt --prompt branch | tail -1) &&
183 prompt_given "$prompt" &&
185 restore_test_defaults
188 # git-difftool falls back to git-mergetool config variables
189 # so test that behavior here
190 test_expect_success 'difftool + mergetool config variables' '
191 remove_config_vars
192 git config merge.tool test-tool &&
193 git config mergetool.test-tool.cmd "cat \$LOCAL" &&
195 diff=$(git difftool --no-prompt branch) &&
196 test "$diff" = "branch" &&
198 # set merge.tool to something bogus, diff.tool to test-tool
199 git config merge.tool bogus-tool &&
200 git config diff.tool test-tool &&
202 diff=$(git difftool --no-prompt branch) &&
203 test "$diff" = "branch" &&
205 restore_test_defaults
208 test_expect_success 'difftool.<tool>.path' '
209 git config difftool.tkdiff.path echo &&
210 diff=$(git difftool --tool=tkdiff --no-prompt branch) &&
211 git config --unset difftool.tkdiff.path &&
212 lines=$(echo "$diff" | grep file | wc -l) &&
213 test "$lines" -eq 1
216 test_done