1#!/bin/sh
2#
3# Copyright (c) 2009 David Aguilar
4#
56
test_description='git-difftool
78
Testing basic diff tool invocation
9'
1011
. ./test-lib.sh
1213
remove_config_vars()
14{
15# Unset all config variables used by git-difftool
16git config --unset diff.tool
17git config --unset difftool.test-tool.cmd
18git config --unset merge.tool
19git config --unset mergetool.test-tool.cmd
20return 0
21}
2223
restore_test_defaults()
24{
25# Restores the test defaults used by several tests
26remove_config_vars
27unset GIT_DIFF_TOOL
28unset GIT_MERGE_TOOL
29unset GIT_DIFFTOOL_NO_PROMPT
30git config diff.tool test-tool &&
31git config difftool.test-tool.cmd 'cat $LOCAL'
32}
3334
# Create a file on master and change it on branch
35test_expect_success 'setup' '
36echo master >file &&
37git add file &&
38git commit -m "added file" &&
3940
git checkout -b branch master &&
41echo branch >file &&
42git commit -a -m "branch changed file" &&
43git checkout master
44'
4546
# Configure a custom difftool.<tool>.cmd and use it
47test_expect_success 'custom commands' '
48restore_test_defaults &&
49git config difftool.test-tool.cmd "cat \$REMOTE" &&
5051
diff=$(git difftool --no-prompt branch) &&
52test "$diff" = "master" &&
5354
restore_test_defaults &&
55diff=$(git difftool --no-prompt branch) &&
56test "$diff" = "branch"
57'
5859
# Ensures that git-difftool ignores bogus --tool values
60test_expect_success 'difftool ignores bad --tool values' '
61diff=$(git difftool --no-prompt --tool=bogus-tool branch)
62test "$?" = 1 &&
63test "$diff" = ""
64'
6566
# Specify the diff tool using $GIT_DIFF_TOOL
67test_expect_success 'GIT_DIFF_TOOL variable' '
68git config --unset diff.tool
69GIT_DIFF_TOOL=test-tool &&
70export GIT_DIFF_TOOL &&
7172
diff=$(git difftool --no-prompt branch) &&
73test "$diff" = "branch" &&
7475
restore_test_defaults
76'
7778
# Test the $GIT_*_TOOL variables and ensure
79# that $GIT_DIFF_TOOL always wins unless --tool is specified
80test_expect_success 'GIT_DIFF_TOOL overrides' '
81git config diff.tool bogus-tool &&
82git config merge.tool bogus-tool &&
8384
GIT_MERGE_TOOL=test-tool &&
85export GIT_MERGE_TOOL &&
86diff=$(git difftool --no-prompt branch) &&
87test "$diff" = "branch" &&
88unset GIT_MERGE_TOOL &&
8990
GIT_MERGE_TOOL=bogus-tool &&
91GIT_DIFF_TOOL=test-tool &&
92export GIT_MERGE_TOOL &&
93export GIT_DIFF_TOOL &&
9495
diff=$(git difftool --no-prompt branch) &&
96test "$diff" = "branch" &&
9798
GIT_DIFF_TOOL=bogus-tool &&
99export GIT_DIFF_TOOL &&
100101
diff=$(git difftool --no-prompt --tool=test-tool branch) &&
102test "$diff" = "branch" &&
103104
restore_test_defaults
105'
106107
# Test that we don't have to pass --no-prompt to difftool
108# when $GIT_DIFFTOOL_NO_PROMPT is true
109test_expect_success 'GIT_DIFFTOOL_NO_PROMPT variable' '
110GIT_DIFFTOOL_NO_PROMPT=true &&
111export GIT_DIFFTOOL_NO_PROMPT &&
112113
diff=$(git difftool branch) &&
114test "$diff" = "branch" &&
115116
restore_test_defaults
117'
118119
# git-difftool falls back to git-mergetool config variables
120# so test that behavior here
121test_expect_success 'difftool + mergetool config variables' '
122remove_config_vars
123git config merge.tool test-tool &&
124git config mergetool.test-tool.cmd "cat \$LOCAL" &&
125126
diff=$(git difftool --no-prompt branch) &&
127test "$diff" = "branch" &&
128129
# set merge.tool to something bogus, diff.tool to test-tool
130git config merge.tool bogus-tool &&
131git config diff.tool test-tool &&
132133
diff=$(git difftool --no-prompt branch) &&
134test "$diff" = "branch" &&
135136
restore_test_defaults
137'
138139
test_expect_success 'difftool.<tool>.path' '
140git config difftool.tkdiff.path echo &&
141diff=$(git difftool --tool=tkdiff --no-prompt branch) &&
142git config --unset difftool.tkdiff.path &&
143lines=$(echo "$diff" | grep file | wc -l) &&
144test "$lines" -eq 1
145'
146147
test_done