difftool: add support for --trust-exit-code
Teach difftool to exit when a diff tool returns a non-zero exit code when either --trust-exit-code is specified or difftool.trustExitCode is true. Forward exit codes from invoked diff tools to the caller when --trust-exit-code is used. Suggested-by: Adri Farr <14farresa@gmail.com> Helped-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
							parent
							
								
									25098690a0
								
							
						
					
					
						commit
						2b52123fcf
					
				|  | @ -91,6 +91,15 @@ instead.  `--no-symlinks` is the default on Windows. | ||||||
| 	the default diff tool will be read from the configured | 	the default diff tool will be read from the configured | ||||||
| 	`diff.guitool` variable instead of `diff.tool`. | 	`diff.guitool` variable instead of `diff.tool`. | ||||||
|  |  | ||||||
|  | --[no-]trust-exit-code:: | ||||||
|  | 	'git-difftool' invokes a diff tool individually on each file. | ||||||
|  | 	Errors reported by the diff tool are ignored by default. | ||||||
|  | 	Use `--trust-exit-code` to make 'git-difftool' exit when an | ||||||
|  | 	invoked diff tool returns a non-zero exit code. | ||||||
|  | + | ||||||
|  | 'git-difftool' will forward the exit code of the invoked tool when | ||||||
|  | '--trust-exit-code' is used. | ||||||
|  |  | ||||||
| See linkgit:git-diff[1] for the full list of supported options. | See linkgit:git-diff[1] for the full list of supported options. | ||||||
|  |  | ||||||
| CONFIG VARIABLES | CONFIG VARIABLES | ||||||
|  | @ -116,6 +125,11 @@ See the `--tool=<tool>` option above for more details. | ||||||
| difftool.prompt:: | difftool.prompt:: | ||||||
| 	Prompt before each invocation of the diff tool. | 	Prompt before each invocation of the diff tool. | ||||||
|  |  | ||||||
|  | difftool.trustExitCode:: | ||||||
|  | 	Exit difftool if the invoked diff tool returns a non-zero exit status. | ||||||
|  | + | ||||||
|  | See the `--trust-exit-code` option above for more details. | ||||||
|  |  | ||||||
| SEE ALSO | SEE ALSO | ||||||
| -------- | -------- | ||||||
| linkgit:git-diff[1]:: | linkgit:git-diff[1]:: | ||||||
|  |  | ||||||
|  | @ -85,6 +85,12 @@ else | ||||||
| 	while test $# -gt 6 | 	while test $# -gt 6 | ||||||
| 	do | 	do | ||||||
| 		launch_merge_tool "$1" "$2" "$5" | 		launch_merge_tool "$1" "$2" "$5" | ||||||
|  | 		status=$? | ||||||
|  | 		if test "$status" != 0 && | ||||||
|  | 			test "$GIT_DIFFTOOL_TRUST_EXIT_CODE" = true | ||||||
|  | 		then | ||||||
|  | 			exit $status | ||||||
|  | 		fi | ||||||
| 		shift 7 | 		shift 7 | ||||||
| 	done | 	done | ||||||
| fi | fi | ||||||
|  |  | ||||||
|  | @ -346,6 +346,7 @@ sub main | ||||||
| 		symlinks => $^O ne 'cygwin' && | 		symlinks => $^O ne 'cygwin' && | ||||||
| 				$^O ne 'MSWin32' && $^O ne 'msys', | 				$^O ne 'MSWin32' && $^O ne 'msys', | ||||||
| 		tool_help => undef, | 		tool_help => undef, | ||||||
|  | 		trust_exit_code => undef, | ||||||
| 	); | 	); | ||||||
| 	GetOptions('g|gui!' => \$opts{gui}, | 	GetOptions('g|gui!' => \$opts{gui}, | ||||||
| 		'd|dir-diff' => \$opts{dirdiff}, | 		'd|dir-diff' => \$opts{dirdiff}, | ||||||
|  | @ -356,6 +357,8 @@ sub main | ||||||
| 		'no-symlinks' => sub { $opts{symlinks} = 0; }, | 		'no-symlinks' => sub { $opts{symlinks} = 0; }, | ||||||
| 		't|tool:s' => \$opts{difftool_cmd}, | 		't|tool:s' => \$opts{difftool_cmd}, | ||||||
| 		'tool-help' => \$opts{tool_help}, | 		'tool-help' => \$opts{tool_help}, | ||||||
|  | 		'trust-exit-code' => \$opts{trust_exit_code}, | ||||||
|  | 		'no-trust-exit-code' => sub { $opts{trust_exit_code} = 0; }, | ||||||
| 		'x|extcmd:s' => \$opts{extcmd}); | 		'x|extcmd:s' => \$opts{extcmd}); | ||||||
|  |  | ||||||
| 	if (defined($opts{help})) { | 	if (defined($opts{help})) { | ||||||
|  | @ -387,6 +390,15 @@ sub main | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	if (!defined $opts{trust_exit_code}) { | ||||||
|  | 		$opts{trust_exit_code} = Git::config_bool('difftool.trustExitCode'); | ||||||
|  | 	} | ||||||
|  | 	if ($opts{trust_exit_code}) { | ||||||
|  | 		$ENV{GIT_DIFFTOOL_TRUST_EXIT_CODE} = 'true'; | ||||||
|  | 	} else { | ||||||
|  | 		$ENV{GIT_DIFFTOOL_TRUST_EXIT_CODE} = 'false'; | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	# In directory diff mode, 'git-difftool--helper' is called once | 	# In directory diff mode, 'git-difftool--helper' is called once | ||||||
| 	# to compare the a/b directories.  In file diff mode, 'git diff' | 	# to compare the a/b directories.  In file diff mode, 'git diff' | ||||||
| 	# will invoke a separate instance of 'git-difftool--helper' for | 	# will invoke a separate instance of 'git-difftool--helper' for | ||||||
|  |  | ||||||
|  | @ -76,6 +76,49 @@ test_expect_success PERL 'difftool forwards arguments to diff' ' | ||||||
| 	rm for-diff | 	rm for-diff | ||||||
| ' | ' | ||||||
|  |  | ||||||
|  | test_expect_success PERL 'difftool ignores exit code' ' | ||||||
|  | 	test_config difftool.error.cmd false && | ||||||
|  | 	git difftool -y -t error branch | ||||||
|  | ' | ||||||
|  |  | ||||||
|  | test_expect_success PERL 'difftool forwards exit code with --trust-exit-code' ' | ||||||
|  | 	test_config difftool.error.cmd false && | ||||||
|  | 	test_must_fail git difftool -y --trust-exit-code -t error branch | ||||||
|  | ' | ||||||
|  |  | ||||||
|  | test_expect_success PERL 'difftool honors difftool.trustExitCode = true' ' | ||||||
|  | 	test_config difftool.error.cmd false && | ||||||
|  | 	test_config difftool.trustExitCode true && | ||||||
|  | 	test_must_fail git difftool -y -t error branch | ||||||
|  | ' | ||||||
|  |  | ||||||
|  | test_expect_success PERL 'difftool honors difftool.trustExitCode = false' ' | ||||||
|  | 	test_config difftool.error.cmd false && | ||||||
|  | 	test_config difftool.trustExitCode false && | ||||||
|  | 	git difftool -y -t error branch | ||||||
|  | ' | ||||||
|  |  | ||||||
|  | test_expect_success PERL 'difftool ignores exit code with --no-trust-exit-code' ' | ||||||
|  | 	test_config difftool.error.cmd false && | ||||||
|  | 	test_config difftool.trustExitCode true && | ||||||
|  | 	git difftool -y --no-trust-exit-code -t error branch | ||||||
|  | ' | ||||||
|  |  | ||||||
|  | test_expect_success PERL 'difftool stops on error with --trust-exit-code' ' | ||||||
|  | 	test_when_finished "rm -f for-diff .git/fail-right-file" && | ||||||
|  | 	test_when_finished "git reset -- for-diff" && | ||||||
|  | 	write_script .git/fail-right-file <<-\EOF && | ||||||
|  | 	echo "$2" | ||||||
|  | 	exit 1 | ||||||
|  | 	EOF | ||||||
|  | 	>for-diff && | ||||||
|  | 	git add for-diff && | ||||||
|  | 	echo file >expect && | ||||||
|  | 	test_must_fail git difftool -y --trust-exit-code \ | ||||||
|  | 		--extcmd .git/fail-right-file branch >actual && | ||||||
|  | 	test_cmp expect actual | ||||||
|  | ' | ||||||
|  |  | ||||||
| test_expect_success PERL 'difftool honors --gui' ' | test_expect_success PERL 'difftool honors --gui' ' | ||||||
| 	difftool_test_setup && | 	difftool_test_setup && | ||||||
| 	test_config merge.tool bogus-tool && | 	test_config merge.tool bogus-tool && | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 David Aguilar
						David Aguilar