t7800-difftool.sh: Simplify the --extcmd test
PATCH v2 1/3 t7800-difftool.sh: Simplify the --extcmd test
Instead of running 'grep', 'echo', and 'wc' we simply compare git-difftool's output against a known good value.
---
This is unchanged from v1 but is included in the series for completeness.
These all apply to 'next', specifically the da/difftool branch.
t/t7800-difftool.sh | 13 +++++-------- 1 files changed, 5 insertions(+), 8 deletions(-)
t/t7800-difftool.sh +5 -8
@@ -15,6 +15,9 @@ if ! test_have_prereq PERL; then test_done fi +LF=' +' + remove_config_vars() { # Unset all config variables used by git-difftool
@@ -219,19 +222,13 @@ test_expect_success 'difftool.<tool>.path' ' restore_test_defaults ' -test_expect_success 'difftool --extcmd=...' ' +test_expect_success 'difftool --extcmd=cat' ' diff=$(git difftool --no-prompt --extcmd=cat branch) && + test "$diff" = branch"$LF"master - 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.6.g627fb.dirty
PATCH v2 2/3 difftool: Add '-x' and as an alias for '--extcmd'
This adds '-x' as a shorthand for the '--extcmd' option. Arguments to '--extcmd' can be specified separately, which was not originally possible.
This also fixes the brief help text so that it mentions both '-x' and '--extcmd'.
---
Changes since v1:
The copyright notice to says "2009, 2010" instead of "2009-2010"
Documentation/git-difftool.txt | 3 ++- git-difftool.perl | 21 ++++++++++++++------- t/t7800-difftool.sh | 8 ++++++++ 3 files changed, 24 insertions(+), 8 deletions(-)
Documentation/git-difftool.txt +2 -1
@@ -7,7 +7,7 @@ git-difftool - Show changes using common diff tools SYNOPSIS -------- -'git difftool' [--tool=<tool>] [-y|--no-prompt|--prompt] [<'git diff' options>] +'git difftool' [<options>] <commit>{0,2} [--] [<path>...] DESCRIPTION -----------
@@ -58,6 +58,7 @@ 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`. +-x <command>:: --extcmd=<command>:: Specify a custom command for viewing diffs. 'git-difftool' ignores the configured defaults and runs
git-difftool.perl +14 -7
@@ -1,5 +1,5 @@ #!/usr/bin/env perl -# Copyright (c) 2009 David Aguilar +# Copyright (c) 2009, 2010 David Aguilar # # This is a wrapper around the GIT_EXTERNAL_DIFF-compatible # git-difftool--helper script.
@@ -23,8 +23,9 @@ my $DIR = abs_path(dirname($0)); sub usage { print << 'USAGE'; -usage: git difftool [-g|--gui] [-t|--tool=<tool>] [-y|--no-prompt] - ["git diff" options] +usage: git difftool [-t|--tool=<tool>] [-x|--extcmd=<cmd>] + [-y|--no-prompt] [-g|--gui] + ['git diff' options] USAGE exit 1; }
@@ -62,14 +63,20 @@ 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; } + if ($arg eq '-x' || $arg eq '--extcmd') { + usage() if $#ARGV <= $idx; + $ENV{GIT_DIFFTOOL_EXTCMD} = $ARGV[$idx + 1]; + $skip_next = 1; + next; + } + if ($arg =~ /^--extcmd=/) { + $ENV{GIT_DIFFTOOL_EXTCMD} = substr($arg, 9); + next; + } if ($arg eq '-g' || $arg eq '--gui') { my $tool = Git::command_oneline('config', 'diff.guitool');
t/t7800-difftool.sh +8 -0
@@ -225,8 +225,16 @@ test_expect_success 'difftool.<tool>.path' ' test_expect_success 'difftool --extcmd=cat' ' diff=$(git difftool --no-prompt --extcmd=cat branch) && test "$diff" = branch"$LF"master +' +test_expect_success 'difftool --extcmd cat' ' + diff=$(git difftool --no-prompt --extcmd cat branch) && + test "$diff" = branch"$LF"master +' +test_expect_success 'difftool -x cat' ' + diff=$(git difftool --no-prompt -x cat branch) && + test "$diff" = branch"$LF"master '
Signature · 1 line
1.6.6.6.g627fb.dirty
PATCH v2 3/3 difftool: Use eval to expand '--extcmd' expressions
In reply to David AguilarIt was not possible to pass quoted commands to '--extcmd'. By using 'eval' we ensure that expressions with spaces and quotes are supported.
---
Updates since v1:
* Uses a more readable quoting style as suggested by J6t.
* We no longer use a subshell.
git-difftool--helper.sh | 3 +-- t/t7800-difftool.sh | 13 +++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-)
git-difftool--helper.sh +1 -2
@@ -48,11 +48,10 @@ launch_merge_tool () { fi if use_ext_cmd; then - $GIT_DIFFTOOL_EXTCMD "$LOCAL" "$REMOTE" + eval $GIT_DIFFTOOL_EXTCMD '"$LOCAL"' '"$REMOTE"' else run_merge_tool "$merge_tool" fi - } if ! use_ext_cmd; then
t/t7800-difftool.sh +13 -0
@@ -235,8 +235,21 @@ test_expect_success 'difftool --extcmd cat' ' test_expect_success 'difftool -x cat' ' diff=$(git difftool --no-prompt -x cat branch) && test "$diff" = branch"$LF"master +' + +test_expect_success 'difftool --extcmd echo arg1' ' + diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"echo\ \$1\" branch) + test "$diff" = file +' +test_expect_success 'difftool --extcmd cat arg1' ' + diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"cat\ \$1\" branch) + test "$diff" = master +' +test_expect_success 'difftool --extcmd cat arg2' ' + diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"cat\ \$2\" branch) + test "$diff" = branch ' test_done
Signature · 1 line
1.6.6.6.g627fb.dirty