Code

difftool: add various git-difftool tests
[git.git] / t / t7800-difftool.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2009 David Aguilar
4 #
6 test_description='git-difftool
8 Testing basic diff tool invocation
9 '
11 . ./test-lib.sh
13 remove_config_vars()
14 {
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 merge.tool
19         git config --unset mergetool.test-tool.cmd
20         return 0
21 }
23 restore_test_defaults()
24 {
25         # Restores the test defaults used by several tests
26         remove_config_vars
27         unset GIT_DIFF_TOOL
28         unset GIT_MERGE_TOOL
29         unset GIT_DIFFTOOL_NO_PROMPT
30         git config diff.tool test-tool &&
31         git config difftool.test-tool.cmd 'cat $LOCAL'
32 }
34 # Create a file on master and change it on branch
35 test_expect_success 'setup' '
36         echo master >file &&
37         git add file &&
38         git commit -m "added file" &&
40         git checkout -b branch master &&
41         echo branch >file &&
42         git commit -a -m "branch changed file" &&
43         git checkout master
44 '
46 # Configure a custom difftool.<tool>.cmd and use it
47 test_expect_success 'custom commands' '
48         restore_test_defaults &&
49         git config difftool.test-tool.cmd "cat \$REMOTE" &&
51         diff=$(git difftool --no-prompt branch) &&
52         test "$diff" = "master" &&
54         restore_test_defaults &&
55         diff=$(git difftool --no-prompt branch) &&
56         test "$diff" = "branch"
57 '
59 # Ensures that git-difftool ignores bogus --tool values
60 test_expect_success 'difftool ignores bad --tool values' '
61         diff=$(git difftool --no-prompt --tool=bogus-tool branch)
62         test "$?" = 1 &&
63         test "$diff" = ""
64 '
66 # Specify the diff tool using $GIT_DIFF_TOOL
67 test_expect_success 'GIT_DIFF_TOOL variable' '
68         git config --unset diff.tool
69         GIT_DIFF_TOOL=test-tool &&
70         export GIT_DIFF_TOOL &&
72         diff=$(git difftool --no-prompt branch) &&
73         test "$diff" = "branch" &&
75         restore_test_defaults
76 '
78 # Test the $GIT_*_TOOL variables and ensure
79 # that $GIT_DIFF_TOOL always wins unless --tool is specified
80 test_expect_success 'GIT_DIFF_TOOL overrides' '
81         git config diff.tool bogus-tool &&
82         git config merge.tool bogus-tool &&
84         GIT_MERGE_TOOL=test-tool &&
85         export GIT_MERGE_TOOL &&
86         diff=$(git difftool --no-prompt branch) &&
87         test "$diff" = "branch" &&
88         unset GIT_MERGE_TOOL &&
90         GIT_MERGE_TOOL=bogus-tool &&
91         GIT_DIFF_TOOL=test-tool &&
92         export GIT_MERGE_TOOL &&
93         export GIT_DIFF_TOOL &&
95         diff=$(git difftool --no-prompt branch) &&
96         test "$diff" = "branch" &&
98         GIT_DIFF_TOOL=bogus-tool &&
99         export GIT_DIFF_TOOL &&
101         diff=$(git difftool --no-prompt --tool=test-tool branch) &&
102         test "$diff" = "branch" &&
104         restore_test_defaults
107 # Test that we don't have to pass --no-prompt to difftool
108 # when $GIT_DIFFTOOL_NO_PROMPT is true
109 test_expect_success 'GIT_DIFFTOOL_NO_PROMPT variable' '
110         GIT_DIFFTOOL_NO_PROMPT=true &&
111         export GIT_DIFFTOOL_NO_PROMPT &&
113         diff=$(git difftool branch) &&
114         test "$diff" = "branch" &&
116         restore_test_defaults
119 # git-difftool falls back to git-mergetool config variables
120 # so test that behavior here
121 test_expect_success 'difftool + mergetool config variables' '
122         remove_config_vars
123         git config merge.tool test-tool &&
124         git config mergetool.test-tool.cmd "cat \$LOCAL" &&
126         diff=$(git difftool --no-prompt branch) &&
127         test "$diff" = "branch" &&
129         # set merge.tool to something bogus, diff.tool to test-tool
130         git config merge.tool bogus-tool &&
131         git config diff.tool test-tool &&
133         diff=$(git difftool --no-prompt branch) &&
134         test "$diff" = "branch" &&
136         restore_test_defaults
139 test_expect_success 'difftool.<tool>.path' '
140         git config difftool.tkdiff.path echo &&
141         diff=$(git difftool --tool=tkdiff --no-prompt branch) &&
142         git config --unset difftool.tkdiff.path &&
143         lines=$(echo "$diff" | grep file | wc -l) &&
144         test "$lines" -eq 1
147 test_done