git-format-patch.txt: general rewordings and cleanups
[git/dscho.git] / t / t7800-difftool.sh
blob2586f864a0df4d8c6fb2c7ca0824a6d53ce0520d
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 remove_config_vars()
15 # Unset all config variables used by git-difftool
16 git config --unset diff.tool
17 git config --unset difftool.test-tool.cmd
18 git config --unset difftool.prompt
19 git config --unset merge.tool
20 git config --unset mergetool.test-tool.cmd
21 return 0
24 restore_test_defaults()
26 # Restores the test defaults used by several tests
27 remove_config_vars
28 unset GIT_DIFF_TOOL
29 unset GIT_MERGE_TOOL
30 unset GIT_DIFFTOOL_PROMPT
31 unset GIT_DIFFTOOL_NO_PROMPT
32 git config diff.tool test-tool &&
33 git config difftool.test-tool.cmd 'cat $LOCAL'
36 prompt_given()
38 prompt="$1"
39 test "$prompt" = "Hit return to launch 'test-tool': branch"
42 # Create a file on master and change it on branch
43 test_expect_success 'setup' '
44 echo master >file &&
45 git add file &&
46 git commit -m "added file" &&
48 git checkout -b branch master &&
49 echo branch >file &&
50 git commit -a -m "branch changed file" &&
51 git checkout master
54 # Configure a custom difftool.<tool>.cmd and use it
55 test_expect_success 'custom commands' '
56 restore_test_defaults &&
57 git config difftool.test-tool.cmd "cat \$REMOTE" &&
59 diff=$(git difftool --no-prompt branch) &&
60 test "$diff" = "master" &&
62 restore_test_defaults &&
63 diff=$(git difftool --no-prompt branch) &&
64 test "$diff" = "branch"
67 # Ensures that git-difftool ignores bogus --tool values
68 test_expect_success 'difftool ignores bad --tool values' '
69 diff=$(git difftool --no-prompt --tool=bogus-tool branch)
70 test "$?" = 1 &&
71 test "$diff" = ""
74 # Specify the diff tool using $GIT_DIFF_TOOL
75 test_expect_success 'GIT_DIFF_TOOL variable' '
76 git config --unset diff.tool
77 GIT_DIFF_TOOL=test-tool &&
78 export GIT_DIFF_TOOL &&
80 diff=$(git difftool --no-prompt branch) &&
81 test "$diff" = "branch" &&
83 restore_test_defaults
86 # Test the $GIT_*_TOOL variables and ensure
87 # that $GIT_DIFF_TOOL always wins unless --tool is specified
88 test_expect_success 'GIT_DIFF_TOOL overrides' '
89 git config diff.tool bogus-tool &&
90 git config merge.tool bogus-tool &&
92 GIT_MERGE_TOOL=test-tool &&
93 export GIT_MERGE_TOOL &&
94 diff=$(git difftool --no-prompt branch) &&
95 test "$diff" = "branch" &&
96 unset GIT_MERGE_TOOL &&
98 GIT_MERGE_TOOL=bogus-tool &&
99 GIT_DIFF_TOOL=test-tool &&
100 export GIT_MERGE_TOOL &&
101 export GIT_DIFF_TOOL &&
103 diff=$(git difftool --no-prompt branch) &&
104 test "$diff" = "branch" &&
106 GIT_DIFF_TOOL=bogus-tool &&
107 export GIT_DIFF_TOOL &&
109 diff=$(git difftool --no-prompt --tool=test-tool branch) &&
110 test "$diff" = "branch" &&
112 restore_test_defaults
115 # Test that we don't have to pass --no-prompt to difftool
116 # when $GIT_DIFFTOOL_NO_PROMPT is true
117 test_expect_success 'GIT_DIFFTOOL_NO_PROMPT variable' '
118 GIT_DIFFTOOL_NO_PROMPT=true &&
119 export GIT_DIFFTOOL_NO_PROMPT &&
121 diff=$(git difftool branch) &&
122 test "$diff" = "branch" &&
124 restore_test_defaults
127 # git-difftool supports the difftool.prompt variable.
128 # Test that GIT_DIFFTOOL_PROMPT can override difftool.prompt = false
129 test_expect_success 'GIT_DIFFTOOL_PROMPT variable' '
130 git config difftool.prompt false &&
131 GIT_DIFFTOOL_PROMPT=true &&
132 export GIT_DIFFTOOL_PROMPT &&
134 prompt=$(echo | git difftool --prompt branch | tail -1) &&
135 prompt_given "$prompt" &&
137 restore_test_defaults
140 # Test that we don't have to pass --no-prompt when difftool.prompt is false
141 test_expect_success 'difftool.prompt config variable is false' '
142 git config difftool.prompt false &&
144 diff=$(git difftool branch) &&
145 test "$diff" = "branch" &&
147 restore_test_defaults
150 # Test that the -y flag can override difftool.prompt = true
151 test_expect_success 'difftool.prompt can overridden with -y' '
152 git config difftool.prompt true &&
154 diff=$(git difftool -y branch) &&
155 test "$diff" = "branch" &&
157 restore_test_defaults
160 # Test that the --prompt flag can override difftool.prompt = false
161 test_expect_success 'difftool.prompt can overridden with --prompt' '
162 git config difftool.prompt false &&
164 prompt=$(echo | git difftool --prompt branch | tail -1) &&
165 prompt_given "$prompt" &&
167 restore_test_defaults
170 # Test that the last flag passed on the command-line wins
171 test_expect_success 'difftool last flag wins' '
172 diff=$(git difftool --prompt --no-prompt branch) &&
173 test "$diff" = "branch" &&
175 restore_test_defaults &&
177 prompt=$(echo | git difftool --no-prompt --prompt branch | tail -1) &&
178 prompt_given "$prompt" &&
180 restore_test_defaults
183 # git-difftool falls back to git-mergetool config variables
184 # so test that behavior here
185 test_expect_success 'difftool + mergetool config variables' '
186 remove_config_vars
187 git config merge.tool test-tool &&
188 git config mergetool.test-tool.cmd "cat \$LOCAL" &&
190 diff=$(git difftool --no-prompt branch) &&
191 test "$diff" = "branch" &&
193 # set merge.tool to something bogus, diff.tool to test-tool
194 git config merge.tool bogus-tool &&
195 git config diff.tool test-tool &&
197 diff=$(git difftool --no-prompt branch) &&
198 test "$diff" = "branch" &&
200 restore_test_defaults
203 test_expect_success 'difftool.<tool>.path' '
204 git config difftool.tkdiff.path echo &&
205 diff=$(git difftool --tool=tkdiff --no-prompt branch) &&
206 git config --unset difftool.tkdiff.path &&
207 lines=$(echo "$diff" | grep file | wc -l) &&
208 test "$lines" -eq 1
211 test_done