From 23218bbd2ea7f919b93245489e544a55165ec466 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Tue, 22 Dec 2009 21:27:13 -0800 Subject: t7800-difftool: Set a bogus tool for use by tests If a difftool test has an error then running the git test suite may end up invoking a GUI diff tool. We now guard against this by setting a difftool.bogus-tool.cmd variable. The tests already used --tool=bogus-tool in various places so this is simply ensuring that nothing ever falls back and finds a real diff tool. Signed-off-by: David Aguilar Signed-off-by: Junio C Hamano diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index fff6a6d..707a0f5 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -36,6 +36,7 @@ restore_test_defaults() unset GIT_DIFFTOOL_NO_PROMPT git config diff.tool test-tool && git config difftool.test-tool.cmd 'cat $LOCAL' + git config difftool.bogus-tool.cmd false } prompt_given() @@ -71,7 +72,7 @@ test_expect_success 'custom commands' ' # Ensures that git-difftool ignores bogus --tool values test_expect_success 'difftool ignores bad --tool values' ' - diff=$(git difftool --no-prompt --tool=bogus-tool branch) + diff=$(git difftool --no-prompt --tool=bad-tool branch) test "$?" = 1 && test "$diff" = "" ' -- cgit v0.10.2-6-g49f6 From 4cefa495ca91ad833084ebf3f73c77997920ae9b Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Tue, 22 Dec 2009 21:27:14 -0800 Subject: git-difftool: Add '--gui' for selecting a GUI tool Users might prefer to have git-difftool use a different tool when run from a Git GUI. This teaches git-difftool to honor 'diff.guitool' when the '--gui' option is specified. This allows users to configure their preferred command-line diff tool in 'diff.tool' and a GUI diff tool in 'diff.guitool'. Reference: http://article.gmane.org/gmane.comp.version-control.git/133386 Signed-off-by: David Aguilar Signed-off-by: Junio C Hamano diff --git a/Documentation/git-difftool.txt b/Documentation/git-difftool.txt index 8e9aed6..a5bce62 100644 --- a/Documentation/git-difftool.txt +++ b/Documentation/git-difftool.txt @@ -58,6 +58,12 @@ 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`. +-g:: +--gui:: + When 'git-difftool' is invoked with the `-g` or `--gui` option + the default diff tool will be read from the configured + `diff.guitool` variable instead of `diff.tool`. + See linkgit:git-diff[1] for the full list of supported options. CONFIG VARIABLES @@ -68,6 +74,9 @@ difftool equivalents have not been defined. diff.tool:: The default diff tool to use. +diff.guitool:: + The default diff tool to use when `--gui` is specified. + difftool..path:: Override the path for the given tool. This is useful in case your tool is not in the PATH. diff --git a/git-difftool.perl b/git-difftool.perl index ba5e60a..8c836e4 100755 --- a/git-difftool.perl +++ b/git-difftool.perl @@ -15,13 +15,16 @@ use warnings; use Cwd qw(abs_path); use File::Basename qw(dirname); +require Git; + my $DIR = abs_path(dirname($0)); sub usage { print << 'USAGE'; -usage: git difftool [--tool=] [-y|--no-prompt] ["git diff" options] +usage: git difftool [-g|--gui] [-t|--tool=] [-y|--no-prompt] + ["git diff" options] USAGE exit 1; } @@ -63,6 +66,14 @@ sub generate_command $ENV{GIT_DIFF_TOOL} = substr($arg, 7); next; } + if ($arg eq '-g' || $arg eq '--gui') { + my $tool = Git::command_oneline('config', + 'diff.guitool'); + if (length($tool)) { + $ENV{GIT_DIFF_TOOL} = $tool; + } + next; + } if ($arg eq '-y' || $arg eq '--no-prompt') { $ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true'; delete $ENV{GIT_DIFFTOOL_PROMPT}; diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index 707a0f5..9bf6c98 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -19,6 +19,7 @@ remove_config_vars() { # Unset all config variables used by git-difftool git config --unset diff.tool + git config --unset diff.guitool git config --unset difftool.test-tool.cmd git config --unset difftool.prompt git config --unset merge.tool @@ -77,6 +78,17 @@ test_expect_success 'difftool ignores bad --tool values' ' test "$diff" = "" ' +test_expect_success 'difftool honors --gui' ' + git config merge.tool bogus-tool && + git config diff.tool bogus-tool && + git config diff.guitool test-tool && + + diff=$(git difftool --no-prompt --gui branch) && + test "$diff" = "branch" && + + restore_test_defaults +' + # Specify the diff tool using $GIT_DIFF_TOOL test_expect_success 'GIT_DIFF_TOOL variable' ' git config --unset diff.tool -- cgit v0.10.2-6-g49f6 From db367136605868f5971d42501a48820ccdcb8b08 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sat, 9 Jan 2010 20:02:40 -0800 Subject: 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. Signed-off-by: David Aguilar Signed-off-by: Junio C Hamano diff --git a/git-difftool--helper.sh b/git-difftool--helper.sh index 57e8e32..1b13808 100755 --- a/git-difftool--helper.sh +++ b/git-difftool--helper.sh @@ -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" } -- cgit v0.10.2-6-g49f6 From 61ed71dcff8448b0700ef032aa1f962649306624 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sat, 9 Jan 2010 20:02:41 -0800 Subject: 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. Signed-off-by: David Aguilar Signed-off-by: Junio C Hamano diff --git a/git-difftool--helper.sh b/git-difftool--helper.sh index 1b13808..3621f28 100755 --- a/git-difftool--helper.sh +++ b/git-difftool--helper.sh @@ -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 diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index 9bf6c98..eca51a8 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -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) && -- cgit v0.10.2-6-g49f6 From 1c6f5b52b7b13bbc6cf404cb5ef9e64fda37655c Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sat, 9 Jan 2010 20:02:42 -0800 Subject: difftool: Allow specifying unconfigured commands with --extcmd git-difftool requires difftool..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 Signed-off-by: Junio C Hamano diff --git a/Documentation/git-difftool.txt b/Documentation/git-difftool.txt index a5bce62..f67d2db 100644 --- a/Documentation/git-difftool.txt +++ b/Documentation/git-difftool.txt @@ -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=:: + 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 diff --git a/git-difftool--helper.sh b/git-difftool--helper.sh index 3621f28..d806eae 100755 --- a/git-difftool--helper.sh +++ b/git-difftool--helper.sh @@ -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' diff --git a/git-difftool.perl b/git-difftool.perl index 8c836e4..f8ff245 100755 --- a/git-difftool.perl +++ b/git-difftool.perl @@ -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; diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index eca51a8..8ee186a 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -214,7 +214,24 @@ test_expect_success 'difftool..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 -- cgit v0.10.2-6-g49f6 From 3bdfd44309822d4a2c49d381999ad5cc7e61ed5f Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sat, 9 Jan 2010 20:02:43 -0800 Subject: git-diff.txt: Link to git-difftool Signed-off-by: David Aguilar Signed-off-by: Junio C Hamano diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt index 0ac7112..723a648 100644 --- a/Documentation/git-diff.txt +++ b/Documentation/git-diff.txt @@ -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 ------ -- cgit v0.10.2-6-g49f6 From a9e11220c2656cc5d7baac4d0735c04f9be46438 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Fri, 15 Jan 2010 14:03:42 -0800 Subject: 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. Signed-off-by: David Aguilar Signed-off-by: Junio C Hamano diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index 8ee186a..1d9e07b 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -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..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 -- cgit v0.10.2-6-g49f6 From f47f1e2ce8b4022113120b32decb4436341dc3aa Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Fri, 15 Jan 2010 14:03:43 -0800 Subject: 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'. Signed-off-by: David Aguilar Signed-off-by: Junio C Hamano diff --git a/Documentation/git-difftool.txt b/Documentation/git-difftool.txt index f67d2db..5c68cff 100644 --- a/Documentation/git-difftool.txt +++ b/Documentation/git-difftool.txt @@ -7,7 +7,7 @@ git-difftool - Show changes using common diff tools SYNOPSIS -------- -'git difftool' [--tool=] [-y|--no-prompt|--prompt] [<'git diff' options>] +'git difftool' [] {0,2} [--] [...] 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 :: --extcmd=:: Specify a custom command for viewing diffs. 'git-difftool' ignores the configured defaults and runs diff --git a/git-difftool.perl b/git-difftool.perl index f8ff245..d975d07 100755 --- a/git-difftool.perl +++ b/git-difftool.perl @@ -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=] [-y|--no-prompt] - ["git diff" options] +usage: git difftool [-t|--tool=] [-x|--extcmd=] + [-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'); diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index 1d9e07b..69e1c34 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -225,8 +225,16 @@ test_expect_success 'difftool..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 ' -- cgit v0.10.2-6-g49f6 From 9f3d54d193d9edcf443c9dd62789af5e8e47635c Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Fri, 15 Jan 2010 14:03:44 -0800 Subject: difftool: Use eval to expand '--extcmd' expressions It was not possible to pass quoted commands to '--extcmd'. By using 'eval' we ensure that expressions with spaces and quotes are supported. Signed-off-by: David Aguilar Signed-off-by: Junio C Hamano diff --git a/git-difftool--helper.sh b/git-difftool--helper.sh index d806eae..69f6bce 100755 --- a/git-difftool--helper.sh +++ b/git-difftool--helper.sh @@ -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 diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index 69e1c34..a183f1d 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -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 -- cgit v0.10.2-6-g49f6 From c8a5672ea5cf593708b29f8279bd651c16047c6e Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Fri, 15 Jan 2010 19:10:03 -0800 Subject: difftool: Update copyright notices to list each year separately This is http://www.gnu.org/licenses/gpl-howto.html advises. Signed-off-by: David Aguilar Signed-off-by: Junio C Hamano diff --git a/git-difftool--helper.sh b/git-difftool--helper.sh index 69f6bce..e43b5d6 100755 --- a/git-difftool--helper.sh +++ b/git-difftool--helper.sh @@ -3,7 +3,7 @@ # This script is typically launched by using the 'git difftool' # convenience command. # -# Copyright (c) 2009-2010 David Aguilar +# Copyright (c) 2009, 2010 David Aguilar TOOL_MODE=diff . git-mergetool--lib diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index a183f1d..fad5472 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (c) 2009 David Aguilar +# Copyright (c) 2009, 2010 David Aguilar # test_description='git-difftool -- cgit v0.10.2-6-g49f6