{"thread":{"id":"43793","subject":"git difftool and git mergetool aren't returning errors when the tool has issues","startedAt":"2016-08-12T07:13:45Z","lastAt":"2016-08-14T09:51:26Z","messageCount":5,"participants":["Tom Tanner (BLOOMBERG/ LONDON)","John Keeping","Junio C Hamano","David Aguilar"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"298829","messageId":"57AD772501C207A400390148_0_15304@p057","threadId":"43793","inReplyTo":null,"subject":"git difftool and git mergetool aren't returning errors when the tool has issues","fromName":"Tom Tanner (BLOOMBERG/ LONDON)","fromEmail":"ttanner2@bloomberg.net","sentAt":null,"receivedAt":"2016-08-12T07:13:45Z","isPatch":false,"sender":{"key":"ttanner2@bloomberg.net","avatar":null},"body":"For instance, if you set your diff/mergetool to meld and you don't have it installed:\n> git difftool\n\nViewing (1/1): 'blah'\nLaunch 'meld' [Y/n]? y\n/home/ttanner/bin/meld[8]: /opt/swt/bin/meld: not found\n> echo $?\n0\n\n> /home/ttanner/bin/meld\n/home/ttanner/bin/meld[8]: /opt/swt/bin/meld: not found\n> echo $?\n127\n\nor\n> env DISPLAY=wibble git difftool\n\nViewing (1/1): blah'\nLaunch 'xxdiff' [Y/n]? y\nxxdiff: cannot connect to X server wibble\n> echo $?\n0\n> env DISPLAY=wibble xxdiff thisfile thatfile\nxxdiff: cannot connect to X server wibble\n> echo $?\n1\nand this one (with DISPLAY unset because it was being run elsewhere)\n> git mergtool\nNormal merge conflict for 'blah: \n{local}: modified file \n{remote}: modified file \nCould not find ':' in DISPLAY: yeah, right \nXIO: fatal IO error 73 (Connection reset by peer) on X server \"server:66.0\" \nafter 0 requests (0 known processed) with 0 events remaining. \n> echo $?\n0\nwhich last looked like a successful merge to a script, because it returned 0."},{"id":"298962","messageId":"20160813103639.mxscvfyztee4hbvh@john.keeping.me.uk","threadId":"43793","inReplyTo":"57AD772501C207A400390148_0_15304@p057","subject":"Re: git difftool and git mergetool aren't returning errors when the tool has issues","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2016-08-13T10:36:39Z","receivedAt":"2016-08-13T10:36:51Z","isPatch":false,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"On Fri, Aug 12, 2016 at 07:13:41AM -0000, Tom Tanner (BLOOMBERG/ LONDON) wrote:\n> For instance, if you set your diff/mergetool to meld and you don't have it installed:\n> > git difftool\n> \n> Viewing (1/1): 'blah'\n> Launch 'meld' [Y/n]? y\n> /home/ttanner/bin/meld[8]: /opt/swt/bin/meld: not found\n> > echo $?\n> 0\n> \n> > /home/ttanner/bin/meld\n> /home/ttanner/bin/meld[8]: /opt/swt/bin/meld: not found\n> > echo $?\n> 127\n\nHave you looked at the --trust-exit-code option to git-difftool?\n\nIt would be nice if there was a way to differentiate between complete\nfailure and just the diff tool exiting with a non-zero return status\nbecause the files differ, but I'm not sure whether we can do that\nreliably.  POSIX uses 127 and 126 as errors that mean the command didn't\nrun [1] so it may be sensible to to treat those as special values.\n\n[1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_08_02\n"},{"id":"298964","messageId":"20160813113028.uwedje6fzuc3cuzr@john.keeping.me.uk","threadId":"43793","inReplyTo":"20160813103639.mxscvfyztee4hbvh@john.keeping.me.uk","subject":"[PATCH] difftool: always honor \"command not found\" exit code","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2016-08-13T11:30:28Z","receivedAt":"2016-08-13T11:30:41Z","isPatch":true,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"At the moment difftool's \"trust exit code\" logic always suppresses the\nexit status of the diff utility we invoke.  This is useful because we\ndon't want to exit just because diff returned \"1\" because the files\ndiffer, but it's confusing if the shell returns an error because the\nselected diff utility is not found.\n\nPOSIX specifies 127 as the exit status for \"command not found\" and 126\nfor \"command found but is not executable\" [1] and at least bash and dash\nfollow this specification, while diff utilities generally use \"1\" for\nthe exit status we want to ignore.\n\nHandle 126 and 127 as special values, assuming that they always mean\nthat the command could not be executed.\n\n[1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_08_02\n\nSigned-off-by: John Keeping <john@keeping.me.uk>\n---\nOn Sat, Aug 13, 2016 at 11:36:39AM +0100, John Keeping wrote:\n> It would be nice if there was a way to differentiate between complete\n> failure and just the diff tool exiting with a non-zero return status\n> because the files differ, but I'm not sure whether we can do that\n> reliably.  POSIX uses 127 and 126 as errors that mean the command didn't\n> run [1] so it may be sensible to to treat those as special values.\n\nSomething like this perhaps?  I think this is probably safe, but it's\nalways possible that some diff utility does use 126 or 127 as a \"normal\"\nexit status.  I'm not sure what we can do about that other than add a\n\"really, really don't trust the exit status\" option!\n\n git-difftool--helper.sh | 18 ++++++++++++++----\n t/t7800-difftool.sh     |  6 ++++++\n 2 files changed, 20 insertions(+), 4 deletions(-)\n\ndiff --git a/git-difftool--helper.sh b/git-difftool--helper.sh\nindex 84d6cc0..68877d4 100755\n--- a/git-difftool--helper.sh\n+++ b/git-difftool--helper.sh\n@@ -86,11 +86,21 @@ else\n \tdo\n \t\tlaunch_merge_tool \"$1\" \"$2\" \"$5\"\n \t\tstatus=$?\n-\t\tif test \"$status\" != 0 &&\n-\t\t\ttest \"$GIT_DIFFTOOL_TRUST_EXIT_CODE\" = true\n-\t\tthen\n+\t\tcase \"$status\" in\n+\t\t0)\n+\t\t\t: OK\n+\t\t\t;;\n+\t\t126|127)\n+\t\t\t# Command not found or not executable\n \t\t\texit $status\n-\t\tfi\n+\t\t\t;;\n+\t\t*)\n+\t\t\tif test \"$GIT_DIFFTOOL_TRUST_EXIT_CODE\" = true\n+\t\t\tthen\n+\t\t\t\texit $status\n+\t\t\tfi\n+\t\t\t;;\n+\t\tesac\n \t\tshift 7\n \tdone\n fi\ndiff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh\nindex 2974900..70a2de4 100755\n--- a/t/t7800-difftool.sh\n+++ b/t/t7800-difftool.sh\n@@ -124,6 +124,12 @@ test_expect_success PERL 'difftool stops on error with --trust-exit-code' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success PERL 'difftool honors exit status if command not found' '\n+\ttest_config difftool.nonexistent.cmd i-dont-exist &&\n+\ttest_config difftool.trustExitCode false &&\n+\ttest_must_fail git difftool -y -t nonexistent branch\n+'\n+\n test_expect_success PERL 'difftool honors --gui' '\n \tdifftool_test_setup &&\n \ttest_config merge.tool bogus-tool &&\n-- \n2.9.2.639.g855ae9f\n\n"},{"id":"299257","messageId":"xmqqtweokpcl.fsf@gitster.mtv.corp.google.com","threadId":"43793","inReplyTo":"20160813113028.uwedje6fzuc3cuzr@john.keeping.me.uk","subject":"Re: [PATCH] difftool: always honor \"command not found\" exit code","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-08-14T03:21:14Z","receivedAt":"2016-08-14T08:39:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"John Keeping <john@keeping.me.uk> writes:\n\n> At the moment difftool's \"trust exit code\" logic always suppresses the\n> exit status of the diff utility we invoke.  This is useful because we\n> don't want to exit just because diff returned \"1\" because the files\n> differ, but it's confusing if the shell returns an error because the\n> selected diff utility is not found.\n>\n> POSIX specifies 127 as the exit status for \"command not found\" and 126\n> for \"command found but is not executable\" [1] and at least bash and dash\n> follow this specification, while diff utilities generally use \"1\" for\n> the exit status we want to ignore.\n>\n> Handle 126 and 127 as special values, assuming that they always mean\n> that the command could not be executed.\n\nSounds like a reasonable thing to do.  Will queue; thanks.\n"},{"id":"299263","messageId":"20160813225939.GA21057@gmail.com","threadId":"43793","inReplyTo":"20160813113028.uwedje6fzuc3cuzr@john.keeping.me.uk","subject":"Re: [PATCH] difftool: always honor \"command not found\" exit code","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2016-08-13T22:59:39Z","receivedAt":"2016-08-14T09:51:26Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"On Sat, Aug 13, 2016 at 12:30:28PM +0100, John Keeping wrote:\n> At the moment difftool's \"trust exit code\" logic always suppresses the\n> exit status of the diff utility we invoke.  This is useful because we\n> don't want to exit just because diff returned \"1\" because the files\n> differ, but it's confusing if the shell returns an error because the\n> selected diff utility is not found.\n> \n> POSIX specifies 127 as the exit status for \"command not found\" and 126\n> for \"command found but is not executable\" [1] and at least bash and dash\n> follow this specification, while diff utilities generally use \"1\" for\n> the exit status we want to ignore.\n> \n> Handle 126 and 127 as special values, assuming that they always mean\n> that the command could not be executed.\n> \n> [1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_08_02\n> \n> Signed-off-by: John Keeping <john@keeping.me.uk>\n\nLooks good to me, thanks.\n\nAcked-by: David Aguilar <davvid@gmail.com>\n\n> ---\n> On Sat, Aug 13, 2016 at 11:36:39AM +0100, John Keeping wrote:\n> > It would be nice if there was a way to differentiate between complete\n> > failure and just the diff tool exiting with a non-zero return status\n> > because the files differ, but I'm not sure whether we can do that\n> > reliably.  POSIX uses 127 and 126 as errors that mean the command didn't\n> > run [1] so it may be sensible to to treat those as special values.\n> \n> Something like this perhaps?  I think this is probably safe, but it's\n> always possible that some diff utility does use 126 or 127 as a \"normal\"\n> exit status.  I'm not sure what we can do about that oaaaather than add a\n> \"really, really don't trust the exit status\" option!\n\n\nWe can always add a mechanism for tool-specific error codes\nlater if we ever end up needing it, but this seems sufficient.\n\ncheers,\n-- \nDavid\n"}]}