threads / patch / 23206

patchdifftool: Fix '--gui' when diff.guitool is unconfigured

Subject: [PATCH] difftool: Fix '--gui' when diff.guitool is unconfigured

## tl;dr

2 messages between Mar 27, 2010 and Mar 28, 2010. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

David Aguilar· Mar 27, 2010, 21:58 UTC · lore

When diff.guitool is unconfigured and "--gui" is specified git-difftool dies with the following error message:

	config diff.guitool: command returned error: 1

Catch the error so that the "--gui" flag is a no-op when diff.guitool is unconfigured.

Signed-off-by: David Aguilar <davvid@gmail.com>
---
This is probably 'maint' material.
 git-difftool.perl   |   12 +++++++-----
 t/t7800-difftool.sh |    9 +++++++++
 2 files changed, 16 insertions(+), 5 deletions(-)
Show changes to 2 files +16 −5

git-difftool.perl, t/t7800-difftool.sh

diff --git a/git-difftool.perl b/git-difftool.perl
index d975d07..adc42de 100755
--- a/git-difftool.perl
+++ b/git-difftool.perl
@@ -78,11 +78,13 @@ sub generate_command
 			next;
 		}
 		if ($arg eq '-g' || $arg eq '--gui') {
-			my $tool = Git::command_oneline('config',
-			                                'diff.guitool');
-			if (length($tool)) {
-				$ENV{GIT_DIFF_TOOL} = $tool;
-			}
+			eval {
+				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') {
diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
index 19c72f5..1de83ef 100755
--- a/t/t7800-difftool.sh
+++ b/t/t7800-difftool.sh
@@ -92,6 +92,15 @@ test_expect_success 'difftool honors --gui' '
 	restore_test_defaults
 '
 
+test_expect_success 'difftool --gui works without configured diff.guitool' '
+	git config diff.tool 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
-- 
1.7.0.3.291.g5e4f6
Junio C Hamano· Mar 28, 2010, 16:29 UTC · re: David Aguilar · lore

Re: [PATCH] difftool: Fix '--gui' when diff.guitool is unconfigured

David Aguilar <davvid@gmail.com> writes:
Show 9 quoted lines
> When diff.guitool is unconfigured and "--gui" is specified
> git-difftool dies with the following error message:
>
> 	config diff.guitool: command returned error: 1
>
> Catch the error so that the "--gui" flag is a no-op when
> diff.guitool is unconfigured.
>
> Signed-off-by: David Aguilar <davvid@gmail.com>
Makes sense; thanks.
Show 52 quoted lines
>
> This is probably 'maint' material.
>
>  git-difftool.perl   |   12 +++++++-----
>  t/t7800-difftool.sh |    9 +++++++++
>  2 files changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/git-difftool.perl b/git-difftool.perl
> index d975d07..adc42de 100755
> --- a/git-difftool.perl
> +++ b/git-difftool.perl
> @@ -78,11 +78,13 @@ sub generate_command
>  			next;
>  		}
>  		if ($arg eq '-g' || $arg eq '--gui') {
> -			my $tool = Git::command_oneline('config',
> -			                                'diff.guitool');
> -			if (length($tool)) {
> -				$ENV{GIT_DIFF_TOOL} = $tool;
> -			}
> +			eval {
> +				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') {
> diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
> index 19c72f5..1de83ef 100755
> --- a/t/t7800-difftool.sh
> +++ b/t/t7800-difftool.sh
> @@ -92,6 +92,15 @@ test_expect_success 'difftool honors --gui' '
>  	restore_test_defaults
>  '
>  
> +test_expect_success 'difftool --gui works without configured diff.guitool' '
> +	git config diff.tool 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
> -- 
> 1.7.0.3.291.g5e4f6

← back to recent threads