@matheusbsbs / matheus-bagliano / commits / 1c6f5b52b7
Fork 0

difftool: Allow specifying unconfigured commands with --extcmd

git-difftool requires difftool.<tool>.cmd configuration even when tools use the standard "$diffcmd $from $to" form. This teaches git-difftool to run these tools in lieu of configuration by allowing the command to be specified on the command line. Reference: http://article.gmane.org/gmane.comp.version-control.git/133377 Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Aguilar committed Jan 9, 2010 at 20:02 UTC 1c6f5b52b7b13bbc6cf404cb5ef9e64fda37655c
4 files changed +50 -8
Documentation/git-difftool.txt
+5
@@ -58,6 +58,11 @@ is set to the name of the temporary file containing the contents
58 of the diff post-image. `$BASE` is provided for compatibility
59 with custom merge tool commands and has the same value as `$LOCAL`.
60
61 +--extcmd=<command>::
62 + Specify a custom command for viewing diffs.
63 + 'git-difftool' ignores the configured defaults and runs
64 + `$command $LOCAL $REMOTE` when this option is specified.
65 +
66 -g::
67 --gui::
68 When 'git-difftool' is invoked with the `-g` or `--gui` option
git-difftool--helper.sh
+23 -7
@@ -19,6 +19,11 @@ should_prompt () {
19 fi
20 }
21
22 +# Indicates that --extcmd=... was specified
23 +use_ext_cmd () {
24 + test -n "$GIT_DIFFTOOL_EXTCMD"
25 +}
26 +
27 launch_merge_tool () {
28 # Merged is the filename as it appears in the work tree
29 # Local is the contents of a/filename
@@ -33,18 +38,29 @@ launch_merge_tool () {
38 # the user with the real $MERGED name before launching $merge_tool.
39 if should_prompt; then
40 printf "\nViewing: '$MERGED'\n"
36 - printf "Hit return to launch '%s': " "$merge_tool"
41 + if use_ext_cmd; then
42 + printf "Hit return to launch '%s': " \
43 + "$GIT_DIFFTOOL_EXTCMD"
44 + else
45 + printf "Hit return to launch '%s': " "$merge_tool"
46 + fi
47 read ans
48 fi
49
40 - run_merge_tool "$merge_tool"
50 + if use_ext_cmd; then
51 + $GIT_DIFFTOOL_EXTCMD "$LOCAL" "$REMOTE"
52 + else
53 + run_merge_tool "$merge_tool"
54 + fi
55 +
56 }
57
43 -# GIT_DIFF_TOOL indicates that --tool=... was specified
44 -if test -n "$GIT_DIFF_TOOL"; then
45 - merge_tool="$GIT_DIFF_TOOL"
46 -else
47 - merge_tool="$(get_merge_tool)" || exit
58 +if ! use_ext_cmd; then
59 + if test -n "$GIT_DIFF_TOOL"; then
60 + merge_tool="$GIT_DIFF_TOOL"
61 + else
62 + merge_tool="$(get_merge_tool)" || exit
63 + fi
64 fi
65
66 # Launch the merge tool on each path provided by 'git diff'
git-difftool.perl
+4
@@ -62,6 +62,10 @@ sub generate_command
62 $skip_next = 1;
63 next;
64 }
65 + if ($arg =~ /^--extcmd=/) {
66 + $ENV{GIT_DIFFTOOL_EXTCMD} = substr($arg, 9);
67 + next;
68 + }
69 if ($arg =~ /^--tool=/) {
70 $ENV{GIT_DIFF_TOOL} = substr($arg, 7);
71 next;
t/t7800-difftool.sh
+18 -1
@@ -214,7 +214,24 @@ test_expect_success 'difftool.<tool>.path' '
214 diff=$(git difftool --tool=tkdiff --no-prompt branch) &&
215 git config --unset difftool.tkdiff.path &&
216 lines=$(echo "$diff" | grep file | wc -l) &&
217 - test "$lines" -eq 1
217 + test "$lines" -eq 1 &&
218 +
219 + restore_test_defaults
220 +'
221 +
222 +test_expect_success 'difftool --extcmd=...' '
223 + diff=$(git difftool --no-prompt --extcmd=cat branch) &&
224 +
225 + lines=$(echo "$diff" | wc -l) &&
226 + test "$lines" -eq 2 &&
227 +
228 + lines=$(echo "$diff" | grep master | wc -l) &&
229 + test "$lines" -eq 1 &&
230 +
231 + lines=$(echo "$diff" | grep branch | wc -l) &&
232 + test "$lines" -eq 1 &&
233 +
234 + restore_test_defaults
235 '
236
237 test_done