{"thread":{"id":"37810","subject":"Quit git difftool on error code","startedAt":"2014-10-25T10:40:37Z","lastAt":"2014-10-26T07:31:05Z","messageCount":4,"participants":["Adri Farr","David Aguilar","Johannes Sixt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"251044","messageId":"CAPfWmhgS8JXyXz5qp04+faqjdeHsydBz-fui-HeNhF3wYLv71g@mail.gmail.com","threadId":"37810","inReplyTo":null,"subject":"Quit git difftool on error code","fromName":"Adri Farr","fromEmail":"14farresa@gmail.com","sentAt":"2014-10-25T10:40:37Z","receivedAt":"2014-10-25T10:40:37Z","isPatch":false,"sender":{"key":"14farresa@gmail.com","avatar":null},"body":"Hello!,\n\nPardon my ignorance, but I haven't found the solution anywhere. Is\nthere a way to make git difftool quit when it receives an error code?\nI have vim as my difftool, and if I quit with an error (:cq) when\nthere are pending files to be diffed, git difftool doesn't quit and\nkeeps pushing me files to be diffed until there are no more pending\nfiles. What is the best way to get out of it?\n\nThank you\n"},{"id":"251052","messageId":"1414286689-62082-1-git-send-email-davvid@gmail.com","threadId":"37810","inReplyTo":"CAPfWmhgS8JXyXz5qp04+faqjdeHsydBz-fui-HeNhF3wYLv71g@mail.gmail.com","subject":"[PATCH] difftool: add support for --trust-exit-code","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2014-10-26T01:24:49Z","receivedAt":"2014-10-26T01:24:49Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"Teach difftool to exit when a diff tool returns a non-zero exit\ncode when either --trust-exit-code is specified or\ndifftool.trustExitCode is true.\n\nForward exit codes from invoked diff tools to the caller when\n--trust-exit-code is used.\n\nSuggested-by: Adri Farr <14farresa@gmail.com>\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n Documentation/git-difftool.txt | 14 ++++++++++++++\n git-difftool--helper.sh        |  7 +++++++\n git-difftool.perl              | 12 ++++++++++++\n t/t7800-difftool.sh            | 43 ++++++++++++++++++++++++++++++++++++++++++\n 4 files changed, 76 insertions(+)\n\ndiff --git a/Documentation/git-difftool.txt b/Documentation/git-difftool.txt\nindex 11887e6..dc843d3 100644\n--- a/Documentation/git-difftool.txt\n+++ b/Documentation/git-difftool.txt\n@@ -91,6 +91,15 @@ instead.  `--no-symlinks` is the default on Windows.\n \tthe default diff tool will be read from the configured\n \t`diff.guitool` variable instead of `diff.tool`.\n \n+--[no-]trust-exit-code::\n+\t'git-difftool' invokes a diff tool individually on each file.\n+\tErrors reported by the diff tool are ignored by default.\n+\tUse `--trust-exit-code` to make 'git-difftool' exit when an an\n+\tinvoked diff tool returns a non-zero exit code.\n++\n+'git-difftool' will forward the exit code of the invoked tool when\n+'--trust-exit-code' is used.\n+\n See linkgit:git-diff[1] for the full list of supported options.\n \n CONFIG VARIABLES\n@@ -116,6 +125,11 @@ See the `--tool=<tool>` option above for more details.\n difftool.prompt::\n \tPrompt before each invocation of the diff tool.\n \n+difftool.trustExitCode::\n+\tExit difftool if the invoked diff tool returns a non-zero exit status.\n++\n+See the `--trust-exit-code` option above for more details.\n+\n SEE ALSO\n --------\n linkgit:git-diff[1]::\ndiff --git a/git-difftool--helper.sh b/git-difftool--helper.sh\nindex 7ef36b9..fdbd768 100755\n--- a/git-difftool--helper.sh\n+++ b/git-difftool--helper.sh\n@@ -62,6 +62,8 @@ launch_merge_tool () {\n \telse\n \t\trun_merge_tool \"$merge_tool\"\n \tfi\n+\tstatus=$?\n+\treturn $status\n }\n \n if ! use_ext_cmd\n@@ -85,5 +87,10 @@ else\n \tdo\n \t\tlaunch_merge_tool \"$1\" \"$2\" \"$5\"\n \t\tshift 7\n+\t\tif test \"$status\" != 0 &&\n+\t\t\ttest \"$GIT_DIFFTOOL_TRUST_EXIT_CODE\" = true\n+\t\tthen\n+\t\t\texit $status\n+\t\tfi\n \tdone\n fi\ndiff --git a/git-difftool.perl b/git-difftool.perl\nindex 598fcc2..7df7c8a 100755\n--- a/git-difftool.perl\n+++ b/git-difftool.perl\n@@ -342,6 +342,7 @@ sub main\n \t\tsymlinks => $^O ne 'cygwin' &&\n \t\t\t\t$^O ne 'MSWin32' && $^O ne 'msys',\n \t\ttool_help => undef,\n+\t\ttrust_exit_code => undef,\n \t);\n \tGetOptions('g|gui!' => \\$opts{gui},\n \t\t'd|dir-diff' => \\$opts{dirdiff},\n@@ -352,6 +353,8 @@ sub main\n \t\t'no-symlinks' => sub { $opts{symlinks} = 0; },\n \t\t't|tool:s' => \\$opts{difftool_cmd},\n \t\t'tool-help' => \\$opts{tool_help},\n+\t\t'trust-exit-code' => \\$opts{trust_exit_code},\n+\t\t'no-trust-exit-code' => sub { $opts{trust_exit_code} = 0; },\n \t\t'x|extcmd:s' => \\$opts{extcmd});\n \n \tif (defined($opts{help})) {\n@@ -383,6 +386,15 @@ sub main\n \t\t}\n \t}\n \n+\tif (!defined $opts{trust_exit_code}) {\n+\t\t$opts{trust_exit_code} = Git::config_bool('difftool.trustExitCode');\n+\t}\n+\tif ($opts{trust_exit_code}) {\n+\t\t$ENV{GIT_DIFFTOOL_TRUST_EXIT_CODE} = 'true';\n+\t} else {\n+\t\t$ENV{GIT_DIFFTOOL_TRUST_EXIT_CODE} = 'false';\n+\t}\n+\n \t# In directory diff mode, 'git-difftool--helper' is called once\n \t# to compare the a/b directories.  In file diff mode, 'git diff'\n \t# will invoke a separate instance of 'git-difftool--helper' for\ndiff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh\nindex dc30a51..2b89b7b 100755\n--- a/t/t7800-difftool.sh\n+++ b/t/t7800-difftool.sh\n@@ -76,6 +76,49 @@ test_expect_success PERL 'difftool forwards arguments to diff' '\n \trm for-diff\n '\n \n+test_expect_success PERL 'difftool ignores exit code' '\n+\ttest_config difftool.error.cmd false &&\n+\tgit difftool -y -t error branch\n+'\n+\n+test_expect_success PERL 'difftool forwards exit code with --trust-exit-code' '\n+\ttest_config difftool.error.cmd false &&\n+\ttest_must_fail git difftool -y --trust-exit-code -t error branch\n+'\n+\n+test_expect_success PERL 'difftool honors difftool.trustExitCode = true' '\n+\ttest_config difftool.error.cmd false &&\n+\ttest_config difftool.trustExitCode true &&\n+\ttest_must_fail git difftool -y -t error branch\n+'\n+\n+test_expect_success PERL 'difftool honors difftool.trustExitCode = false' '\n+\ttest_config difftool.error.cmd false &&\n+\ttest_config difftool.trustExitCode false &&\n+\tgit difftool -y -t error branch\n+'\n+\n+test_expect_success PERL 'difftool ignores exit code with --no-trust-exit-code' '\n+\ttest_config difftool.error.cmd false &&\n+\ttest_config difftool.trustExitCode true &&\n+\tgit difftool -y --no-trust-exit-code -t error branch\n+'\n+\n+write_script fail-right-file <<\\EOF\n+echo \"$2\"\n+exit 1\n+EOF\n+\n+test_expect_success PERL 'difftool stops on error with --trust-exit-code' '\n+\t>for-diff &&\n+\tgit add for-diff &&\n+\techo branch >actual &&\n+\ttest_must_fail git difftool -y --trust-exit-code \\\n+\t\t--extcmd \"$(pwd)/fail-right-file\" branch >actual &&\n+\ttest_cmp expect actual &&\n+\trm -f for-diff fail-right-file\n+'\n+\n test_expect_success PERL 'difftool honors --gui' '\n \tdifftool_test_setup &&\n \ttest_config merge.tool bogus-tool &&\n-- \n2.1.2.556.g2136b5c\n"},{"id":"251053","messageId":"1414287526-80060-1-git-send-email-davvid@gmail.com","threadId":"37810","inReplyTo":"1414286689-62082-1-git-send-email-davvid@gmail.com","subject":"[PATCH v2] difftool: add support for --trust-exit-code","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2014-10-26T01:38:46Z","receivedAt":"2014-10-26T01:38:46Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"Teach difftool to exit when a diff tool returns a non-zero exit\ncode when either --trust-exit-code is specified or\ndifftool.trustExitCode is true.\n\nForward exit codes from invoked diff tools to the caller when\n--trust-exit-code is used.\n\nSuggested-by: Adri Farr <14farresa@gmail.com>\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\nChanges since v1:\n\nThis fixes typos in the documentation (s/an an/an/) and tests.\n\nI'll wait until tomorrow before sending follow-ups in case anyone spots\nany other issues.\n\n Documentation/git-difftool.txt | 14 ++++++++++++++\n git-difftool--helper.sh        |  7 +++++++\n git-difftool.perl              | 12 ++++++++++++\n t/t7800-difftool.sh            | 43 ++++++++++++++++++++++++++++++++++++++++++\n 4 files changed, 76 insertions(+)\n\ndiff --git a/Documentation/git-difftool.txt b/Documentation/git-difftool.txt\nindex 11887e6..333cf6f 100644\n--- a/Documentation/git-difftool.txt\n+++ b/Documentation/git-difftool.txt\n@@ -91,6 +91,15 @@ instead.  `--no-symlinks` is the default on Windows.\n \tthe default diff tool will be read from the configured\n \t`diff.guitool` variable instead of `diff.tool`.\n \n+--[no-]trust-exit-code::\n+\t'git-difftool' invokes a diff tool individually on each file.\n+\tErrors reported by the diff tool are ignored by default.\n+\tUse `--trust-exit-code` to make 'git-difftool' exit when an\n+\tinvoked diff tool returns a non-zero exit code.\n++\n+'git-difftool' will forward the exit code of the invoked tool when\n+'--trust-exit-code' is used.\n+\n See linkgit:git-diff[1] for the full list of supported options.\n \n CONFIG VARIABLES\n@@ -116,6 +125,11 @@ See the `--tool=<tool>` option above for more details.\n difftool.prompt::\n \tPrompt before each invocation of the diff tool.\n \n+difftool.trustExitCode::\n+\tExit difftool if the invoked diff tool returns a non-zero exit status.\n++\n+See the `--trust-exit-code` option above for more details.\n+\n SEE ALSO\n --------\n linkgit:git-diff[1]::\ndiff --git a/git-difftool--helper.sh b/git-difftool--helper.sh\nindex 7ef36b9..fdbd768 100755\n--- a/git-difftool--helper.sh\n+++ b/git-difftool--helper.sh\n@@ -62,6 +62,8 @@ launch_merge_tool () {\n \telse\n \t\trun_merge_tool \"$merge_tool\"\n \tfi\n+\tstatus=$?\n+\treturn $status\n }\n \n if ! use_ext_cmd\n@@ -85,5 +87,10 @@ else\n \tdo\n \t\tlaunch_merge_tool \"$1\" \"$2\" \"$5\"\n \t\tshift 7\n+\t\tif test \"$status\" != 0 &&\n+\t\t\ttest \"$GIT_DIFFTOOL_TRUST_EXIT_CODE\" = true\n+\t\tthen\n+\t\t\texit $status\n+\t\tfi\n \tdone\n fi\ndiff --git a/git-difftool.perl b/git-difftool.perl\nindex 598fcc2..7df7c8a 100755\n--- a/git-difftool.perl\n+++ b/git-difftool.perl\n@@ -342,6 +342,7 @@ sub main\n \t\tsymlinks => $^O ne 'cygwin' &&\n \t\t\t\t$^O ne 'MSWin32' && $^O ne 'msys',\n \t\ttool_help => undef,\n+\t\ttrust_exit_code => undef,\n \t);\n \tGetOptions('g|gui!' => \\$opts{gui},\n \t\t'd|dir-diff' => \\$opts{dirdiff},\n@@ -352,6 +353,8 @@ sub main\n \t\t'no-symlinks' => sub { $opts{symlinks} = 0; },\n \t\t't|tool:s' => \\$opts{difftool_cmd},\n \t\t'tool-help' => \\$opts{tool_help},\n+\t\t'trust-exit-code' => \\$opts{trust_exit_code},\n+\t\t'no-trust-exit-code' => sub { $opts{trust_exit_code} = 0; },\n \t\t'x|extcmd:s' => \\$opts{extcmd});\n \n \tif (defined($opts{help})) {\n@@ -383,6 +386,15 @@ sub main\n \t\t}\n \t}\n \n+\tif (!defined $opts{trust_exit_code}) {\n+\t\t$opts{trust_exit_code} = Git::config_bool('difftool.trustExitCode');\n+\t}\n+\tif ($opts{trust_exit_code}) {\n+\t\t$ENV{GIT_DIFFTOOL_TRUST_EXIT_CODE} = 'true';\n+\t} else {\n+\t\t$ENV{GIT_DIFFTOOL_TRUST_EXIT_CODE} = 'false';\n+\t}\n+\n \t# In directory diff mode, 'git-difftool--helper' is called once\n \t# to compare the a/b directories.  In file diff mode, 'git diff'\n \t# will invoke a separate instance of 'git-difftool--helper' for\ndiff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh\nindex dc30a51..b273e97 100755\n--- a/t/t7800-difftool.sh\n+++ b/t/t7800-difftool.sh\n@@ -76,6 +76,49 @@ test_expect_success PERL 'difftool forwards arguments to diff' '\n \trm for-diff\n '\n \n+test_expect_success PERL 'difftool ignores exit code' '\n+\ttest_config difftool.error.cmd false &&\n+\tgit difftool -y -t error branch\n+'\n+\n+test_expect_success PERL 'difftool forwards exit code with --trust-exit-code' '\n+\ttest_config difftool.error.cmd false &&\n+\ttest_must_fail git difftool -y --trust-exit-code -t error branch\n+'\n+\n+test_expect_success PERL 'difftool honors difftool.trustExitCode = true' '\n+\ttest_config difftool.error.cmd false &&\n+\ttest_config difftool.trustExitCode true &&\n+\ttest_must_fail git difftool -y -t error branch\n+'\n+\n+test_expect_success PERL 'difftool honors difftool.trustExitCode = false' '\n+\ttest_config difftool.error.cmd false &&\n+\ttest_config difftool.trustExitCode false &&\n+\tgit difftool -y -t error branch\n+'\n+\n+test_expect_success PERL 'difftool ignores exit code with --no-trust-exit-code' '\n+\ttest_config difftool.error.cmd false &&\n+\ttest_config difftool.trustExitCode true &&\n+\tgit difftool -y --no-trust-exit-code -t error branch\n+'\n+\n+write_script .git/fail-right-file <<\\EOF\n+echo \"$2\"\n+exit 1\n+EOF\n+\n+test_expect_success PERL 'difftool stops on error with --trust-exit-code' '\n+\t>for-diff &&\n+\tgit add for-diff &&\n+\techo file>expect &&\n+\ttest_must_fail git difftool -y --trust-exit-code \\\n+\t\t--extcmd .git/fail-right-file branch >actual &&\n+\ttest_cmp expect actual &&\n+\trm -f for-diff .git/fail-right-file\n+'\n+\n test_expect_success PERL 'difftool honors --gui' '\n \tdifftool_test_setup &&\n \ttest_config merge.tool bogus-tool &&\n-- \n2.1.2.556.g2136b5c\n"},{"id":"251055","messageId":"544CA339.3000401@kdbg.org","threadId":"37810","inReplyTo":"1414287526-80060-1-git-send-email-davvid@gmail.com","subject":"Re: [PATCH v2] difftool: add support for --trust-exit-code","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2014-10-26T07:31:05Z","receivedAt":"2014-10-26T07:31:05Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 26.10.2014 um 02:38 schrieb David Aguilar:\n> diff --git a/git-difftool--helper.sh b/git-difftool--helper.sh\n> index 7ef36b9..fdbd768 100755\n> --- a/git-difftool--helper.sh\n> +++ b/git-difftool--helper.sh\n> @@ -62,6 +62,8 @@ launch_merge_tool () {\n>  \telse\n>  \t\trun_merge_tool \"$merge_tool\"\n>  \tfi\n> +\tstatus=$?\n> +\treturn $status\n>  }\n>  \n>  if ! use_ext_cmd\n> @@ -85,5 +87,10 @@ else\n>  \tdo\n>  \t\tlaunch_merge_tool \"$1\" \"$2\" \"$5\"\n>  \t\tshift 7\n> +\t\tif test \"$status\" != 0 &&\n> +\t\t\ttest \"$GIT_DIFFTOOL_TRUST_EXIT_CODE\" = true\n> +\t\tthen\n> +\t\t\texit $status\n> +\t\tfi\n\nIf you insert this new code block before the 'shift 7', you can set\nstatus here and do not have to hide it in the helper function.\n\n>  \tdone\n>  fi\n\n-- Hannes\n"}]}