difftool--helper: Update copyright and remove distracting comments
PATCH 1/4 difftool--helper: Update copyright and remove distracting comments
Some of the comments in git-difftool--helper are not needed because the code is sufficiently readable without them.
--- git-difftool--helper.sh | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-)
git-difftool--helper.sh +1 -4
@@ -3,9 +3,8 @@ # This script is typically launched by using the 'git difftool' # convenience command. # -# Copyright (c) 2009 David Aguilar +# Copyright (c) 2009-2010 David Aguilar -# Load common functions from git-mergetool--lib TOOL_MODE=diff . git-mergetool--lib
@@ -20,7 +19,6 @@ should_prompt () { fi } -# Sets up shell variables and runs a merge tool launch_merge_tool () { # Merged is the filename as it appears in the work tree # Local is the contents of a/filename
@@ -39,7 +37,6 @@ launch_merge_tool () { read ans fi - # Run the appropriate merge tool command run_merge_tool "$merge_tool" }
Signature · 1 line
1.6.6.4.g20a38b.dirty
PATCH 2/4 difftool--helper: Remove use of the GIT_MERGE_TOOL variable
An undocumented mis-feature in git-difftool is that it allows you to specify a default difftool by setting GIT_MERGE_TOOL. This behavior was never documented and was included as an oversight back when git-difftool was maintained outside of git.
git-mergetool never honored GIT_MERGE_TOOL so neither should git-difftool.
--- git-difftool--helper.sh | 9 ++++----- t/t7800-difftool.sh | 9 --------- 2 files changed, 4 insertions(+), 14 deletions(-)
git-difftool--helper.sh +4 -5
@@ -40,11 +40,10 @@ launch_merge_tool () { run_merge_tool "$merge_tool" } -# Allow GIT_DIFF_TOOL and GIT_MERGE_TOOL to provide default values -test -n "$GIT_MERGE_TOOL" && merge_tool="$GIT_MERGE_TOOL" -test -n "$GIT_DIFF_TOOL" && merge_tool="$GIT_DIFF_TOOL" - -if test -z "$merge_tool"; then +# GIT_DIFF_TOOL indicates that --tool=... was specified +if test -n "$GIT_DIFF_TOOL"; then + merge_tool="$GIT_DIFF_TOOL" +else merge_tool="$(get_merge_tool)" || exit fi
t/t7800-difftool.sh +0 -9
@@ -32,7 +32,6 @@ restore_test_defaults() # Restores the test defaults used by several tests remove_config_vars unset GIT_DIFF_TOOL - unset GIT_MERGE_TOOL unset GIT_DIFFTOOL_PROMPT unset GIT_DIFFTOOL_NO_PROMPT git config diff.tool test-tool &&
@@ -107,15 +106,7 @@ test_expect_success 'GIT_DIFF_TOOL overrides' ' git config diff.tool bogus-tool && git config merge.tool bogus-tool && - GIT_MERGE_TOOL=test-tool && - export GIT_MERGE_TOOL && - diff=$(git difftool --no-prompt branch) && - test "$diff" = "branch" && - unset GIT_MERGE_TOOL && - - GIT_MERGE_TOOL=bogus-tool && GIT_DIFF_TOOL=test-tool && - export GIT_MERGE_TOOL && export GIT_DIFF_TOOL && diff=$(git difftool --no-prompt branch) &&
Signature · 1 line
1.6.6.4.g20a38b.dirty
PATCH 3/4 difftool: Allow specifying unconfigured commands with --extcmd
In reply to David Aguilargit-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
--- Documentation/git-difftool.txt | 5 +++++ git-difftool--helper.sh | 30 +++++++++++++++++++++++------- git-difftool.perl | 4 ++++ t/t7800-difftool.sh | 19 ++++++++++++++++++- 4 files changed, 50 insertions(+), 8 deletions(-)
Documentation/git-difftool.txt +5 -0
@@ -58,6 +58,11 @@ is set to the name of the temporary file containing the contents of the diff post-image. `$BASE` is provided for compatibility with custom merge tool commands and has the same value as `$LOCAL`. +--extcmd=<command>:: + Specify a custom command for viewing diffs. + 'git-difftool' ignores the configured defaults and runs + `$command $LOCAL $REMOTE` when this option is specified. + -g:: --gui:: When 'git-difftool' is invoked with the `-g` or `--gui` option
git-difftool--helper.sh +23 -7
@@ -19,6 +19,11 @@ should_prompt () { fi } +# Indicates that --extcmd=... was specified +use_ext_cmd () { + test -n "$GIT_DIFFTOOL_EXTCMD" +} + launch_merge_tool () { # Merged is the filename as it appears in the work tree # Local is the contents of a/filename
@@ -33,18 +38,29 @@ launch_merge_tool () { # the user with the real $MERGED name before launching $merge_tool. if should_prompt; then printf "\nViewing: '$MERGED'\n" - printf "Hit return to launch '%s': " "$merge_tool" + if use_ext_cmd; then + printf "Hit return to launch '%s': " \ + "$GIT_DIFFTOOL_EXTCMD" + else + printf "Hit return to launch '%s': " "$merge_tool" + fi read ans fi - run_merge_tool "$merge_tool" + if use_ext_cmd; then + $GIT_DIFFTOOL_EXTCMD "$LOCAL" "$REMOTE" + else + run_merge_tool "$merge_tool" + fi + } -# GIT_DIFF_TOOL indicates that --tool=... was specified -if test -n "$GIT_DIFF_TOOL"; then - merge_tool="$GIT_DIFF_TOOL" -else - merge_tool="$(get_merge_tool)" || exit +if ! use_ext_cmd; then + if test -n "$GIT_DIFF_TOOL"; then + merge_tool="$GIT_DIFF_TOOL" + else + merge_tool="$(get_merge_tool)" || exit + fi fi # Launch the merge tool on each path provided by 'git diff'
git-difftool.perl +4 -0
@@ -62,6 +62,10 @@ sub generate_command $skip_next = 1; next; } + if ($arg =~ /^--extcmd=/) { + $ENV{GIT_DIFFTOOL_EXTCMD} = substr($arg, 9); + next; + } if ($arg =~ /^--tool=/) { $ENV{GIT_DIFF_TOOL} = substr($arg, 7); next;
t/t7800-difftool.sh +18 -1
@@ -214,7 +214,24 @@ test_expect_success 'difftool.<tool>.path' ' diff=$(git difftool --tool=tkdiff --no-prompt branch) && git config --unset difftool.tkdiff.path && lines=$(echo "$diff" | grep file | wc -l) && - test "$lines" -eq 1 + test "$lines" -eq 1 && + + restore_test_defaults +' + +test_expect_success 'difftool --extcmd=...' ' + diff=$(git difftool --no-prompt --extcmd=cat branch) && + + lines=$(echo "$diff" | wc -l) && + test "$lines" -eq 2 && + + lines=$(echo "$diff" | grep master | wc -l) && + test "$lines" -eq 1 && + + lines=$(echo "$diff" | grep branch | wc -l) && + test "$lines" -eq 1 && + + restore_test_defaults ' test_done
Signature · 1 line
1.6.6.4.g20a38b.dirty
PATCH 4/4 git-diff.txt: Link to git-difftool
In reply to David Aguilar--- Documentation/git-diff.txt | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
Documentation/git-diff.txt +4 -0
@@ -157,6 +157,10 @@ $ git diff -R <2> rewrites (very expensive). <2> Output diff in reverse. +SEE ALSO +-------- +linkgit:git-difftool[1]:: + Show changes using common diff tools Author ------
Signature · 1 line
1.6.6.4.g20a38b.dirty