File tree Expand file tree Collapse file tree 4 files changed +50
-8
lines changed
Expand file tree Collapse file tree 4 files changed +50
-8
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,11 @@ is set to the name of the temporary file containing the contents
5858of the diff post-image. `$BASE` is provided for compatibility
5959with custom merge tool commands and has the same value as `$LOCAL`.
6060
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+
6166-g::
6267--gui::
6368 When 'git-difftool' is invoked with the `-g` or `--gui` option
Original file line number Diff line number Diff line change @@ -19,6 +19,11 @@ should_prompt () {
1919 fi
2020}
2121
22+ # Indicates that --extcmd=... was specified
23+ use_ext_cmd () {
24+ test -n " $GIT_DIFFTOOL_EXTCMD "
25+ }
26+
2227launch_merge_tool () {
2328 # Merged is the filename as it appears in the work tree
2429 # Local is the contents of a/filename
@@ -33,18 +38,29 @@ launch_merge_tool () {
3338 # the user with the real $MERGED name before launching $merge_tool.
3439 if should_prompt; then
3540 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
3747 read ans
3848 fi
3949
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+
4156}
4257
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
4864fi
4965
5066# Launch the merge tool on each path provided by 'git diff'
Original file line number Diff line number Diff line change @@ -62,6 +62,10 @@ sub generate_command
6262 $skip_next = 1;
6363 next ;
6464 }
65+ if ($arg =~ / ^--extcmd=/ ) {
66+ $ENV {GIT_DIFFTOOL_EXTCMD } = substr ($arg , 9);
67+ next ;
68+ }
6569 if ($arg =~ / ^--tool=/ ) {
6670 $ENV {GIT_DIFF_TOOL } = substr ($arg , 7);
6771 next ;
Original file line number Diff line number Diff line change @@ -214,7 +214,24 @@ test_expect_success 'difftool.<tool>.path' '
214214 diff=$(git difftool --tool=tkdiff --no-prompt branch) &&
215215 git config --unset difftool.tkdiff.path &&
216216 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
218235'
219236
220237test_done
You can’t perform that action at this time.
0 commit comments