@matheusbsbs / matheus-bagliano / commits / f92f2038a5
Fork 0

difftool: add various git-difftool tests

t7800-difftool.sh tests the various command-line flags, git-config variables, and environment settings supported by git-difftool. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Aguilar committed Apr 7, 2009 at 16:30 UTC f92f2038a5192ac5fc1bb4f38c49906aa45b3f1e
1 file changed +147
t/t7800-difftool.sh new
+147
@@ -0,0 +1,147 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2009 David Aguilar
4 +#
5 +
6 +test_description='git-difftool
7 +
8 +Testing basic diff tool invocation
9 +'
10 +
11 +. ./test-lib.sh
12 +
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 +}
22 +
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 +}
33 +
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" &&
39 +
40 + git checkout -b branch master &&
41 + echo branch >file &&
42 + git commit -a -m "branch changed file" &&
43 + git checkout master
44 +'
45 +
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" &&
50 +
51 + diff=$(git difftool --no-prompt branch) &&
52 + test "$diff" = "master" &&
53 +
54 + restore_test_defaults &&
55 + diff=$(git difftool --no-prompt branch) &&
56 + test "$diff" = "branch"
57 +'
58 +
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 +'
65 +
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 &&
71 +
72 + diff=$(git difftool --no-prompt branch) &&
73 + test "$diff" = "branch" &&
74 +
75 + restore_test_defaults
76 +'
77 +
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 &&
83 +
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 &&
89 +
90 + GIT_MERGE_TOOL=bogus-tool &&
91 + GIT_DIFF_TOOL=test-tool &&
92 + export GIT_MERGE_TOOL &&
93 + export GIT_DIFF_TOOL &&
94 +
95 + diff=$(git difftool --no-prompt branch) &&
96 + test "$diff" = "branch" &&
97 +
98 + GIT_DIFF_TOOL=bogus-tool &&
99 + export GIT_DIFF_TOOL &&
100 +
101 + diff=$(git difftool --no-prompt --tool=test-tool branch) &&
102 + test "$diff" = "branch" &&
103 +
104 + restore_test_defaults
105 +'
106 +
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 &&
112 +
113 + diff=$(git difftool branch) &&
114 + test "$diff" = "branch" &&
115 +
116 + restore_test_defaults
117 +'
118 +
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" &&
125 +
126 + diff=$(git difftool --no-prompt branch) &&
127 + test "$diff" = "branch" &&
128 +
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 &&
132 +
133 + diff=$(git difftool --no-prompt branch) &&
134 + test "$diff" = "branch" &&
135 +
136 + restore_test_defaults
137 +'
138 +
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
145 +'
146 +
147 +test_done