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

difftool: add support for a difftool.prompt config variable

difftool now supports difftool.prompt so that users do not have to pass --no-prompt or hit enter each time a diff tool is launched. The --prompt flag overrides the configuration variable. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Aguilar committed Apr 7, 2009 at 01:21 UTC a904392eaeee1629c0ac14dae8e579bb8497636a
5 files changed +96 -6
Documentation/config.txt
+3
@@ -685,6 +685,9 @@ difftool.<tool>.cmd::
685 is set to the name of the temporary file containing the contents
686 of the diff post-image.
687
688 +difftool.prompt::
689 + Prompt before each invocation of the diff tool.
690 +
691 diff.wordRegex::
692 A POSIX Extended Regular Expression used to determine what is a "word"
693 when performing word-by-word difference calculations. Character
Documentation/git-difftool.txt
+9 -1
@@ -7,7 +7,7 @@ git-difftool - Show changes using common diff tools
7
8 SYNOPSIS
9 --------
10 -'git difftool' [--tool=<tool>] [-y|--no-prompt] [<'git diff' options>]
10 +'git difftool' [--tool=<tool>] [-y|--no-prompt|--prompt] [<'git diff' options>]
11
12 DESCRIPTION
13 -----------
@@ -21,6 +21,11 @@ OPTIONS
21 --no-prompt::
22 Do not prompt before launching a diff tool.
23
24 +--prompt::
25 + Prompt before each invocation of the diff tool.
26 + This is the default behaviour; the option is provided to
27 + override any configuration settings.
28 +
29 -t <tool>::
30 --tool=<tool>::
31 Use the diff tool specified by <tool>.
@@ -72,6 +77,9 @@ difftool.<tool>.cmd::
77 +
78 See the `--tool=<tool>` option above for more details.
79
80 +difftool.prompt::
81 + Prompt before each invocation of the diff tool.
82 +
83 SEE ALSO
84 --------
85 linkgit:git-diff[1]::
git-difftool--helper.sh
+8 -2
@@ -5,9 +5,15 @@
5 #
6 # Copyright (c) 2009 David Aguilar
7
8 -# Set GIT_DIFFTOOL_NO_PROMPT to bypass the per-file prompt.
8 +# difftool.prompt controls the default prompt/no-prompt behavior
9 +# and is overridden with $GIT_DIFFTOOL*_PROMPT.
10 should_prompt () {
10 - test -z "$GIT_DIFFTOOL_NO_PROMPT"
11 + prompt=$(git config --bool difftool.prompt || echo true)
12 + if test "$prompt" = true; then
13 + test -z "$GIT_DIFFTOOL_NO_PROMPT"
14 + else
15 + test -n "$GIT_DIFFTOOL_PROMPT"
16 + fi
17 }
18
19 # This function prepares temporary files and launches the appropriate
git-difftool.perl
+12 -3
@@ -2,9 +2,12 @@
2 # Copyright (c) 2009 David Aguilar
3 #
4 # This is a wrapper around the GIT_EXTERNAL_DIFF-compatible
5 -# git-difftool--helper script. This script exports
6 -# GIT_EXTERNAL_DIFF and GIT_PAGER for use by git, and
7 -# GIT_DIFFTOOL_NO_PROMPT and GIT_DIFF_TOOL for use by git-difftool--helper.
5 +# git-difftool--helper script.
6 +#
7 +# This script exports GIT_EXTERNAL_DIFF and GIT_PAGER for use by git.
8 +# GIT_DIFFTOOL_NO_PROMPT, GIT_DIFFTOOL_PROMPT, and GIT_DIFF_TOOL
9 +# are exported for use by git-difftool--helper.
10 +#
11 # Any arguments that are unknown to this script are forwarded to 'git diff'.
12
13 use strict;
@@ -62,6 +65,12 @@ sub generate_command
65 }
66 if ($arg eq '-y' || $arg eq '--no-prompt') {
67 $ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true';
68 + delete $ENV{GIT_DIFFTOOL_PROMPT};
69 + next;
70 + }
71 + if ($arg eq '--prompt') {
72 + $ENV{GIT_DIFFTOOL_PROMPT} = 'true';
73 + delete $ENV{GIT_DIFFTOOL_NO_PROMPT};
74 next;
75 }
76 if ($arg eq '-h' || $arg eq '--help') {
t/t7800-difftool.sh
+64
@@ -15,6 +15,7 @@ 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
@@ -26,11 +27,18 @@ restore_test_defaults()
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'
34 }
35
36 +prompt_given()
37 +{
38 + prompt="$1"
39 + test "$prompt" = "Hit return to launch 'test-tool': branch"
40 +}
41 +
42 # Create a file on master and change it on branch
43 test_expect_success 'setup' '
44 echo master >file &&
@@ -116,6 +124,62 @@ test_expect_success 'GIT_DIFFTOOL_NO_PROMPT variable' '
124 restore_test_defaults
125 '
126
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 &&
133 +
134 + prompt=$(echo | git difftool --prompt branch | tail -1) &&
135 + prompt_given "$prompt" &&
136 +
137 + restore_test_defaults
138 +'
139 +
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 &&
143 +
144 + diff=$(git difftool branch) &&
145 + test "$diff" = "branch" &&
146 +
147 + restore_test_defaults
148 +'
149 +
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 &&
153 +
154 + diff=$(git difftool -y branch) &&
155 + test "$diff" = "branch" &&
156 +
157 + restore_test_defaults
158 +'
159 +
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 &&
163 +
164 + prompt=$(echo | git difftool --prompt branch | tail -1) &&
165 + prompt_given "$prompt" &&
166 +
167 + restore_test_defaults
168 +'
169 +
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" &&
174 +
175 + restore_test_defaults &&
176 +
177 + prompt=$(echo | git difftool --no-prompt --prompt branch | tail -1) &&
178 + prompt_given "$prompt" &&
179 +
180 + restore_test_defaults
181 +'
182 +
183 # git-difftool falls back to git-mergetool config variables
184 # so test that behavior here
185 test_expect_success 'difftool + mergetool config variables' '