summaryrefslogtreecommitdiff
path: root/t/t4017-diff-retval.sh
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2023-08-21 20:16:26 (GMT)
committerJunio C Hamano <gitster@pobox.com>2023-08-21 22:33:24 (GMT)
commit5ad6e2b495dfb7264fc94dc548af9c0a10901683 (patch)
tree4a96e9a0a974bdb2f2bc2bbbde6a6736fa5c87d0 /t/t4017-diff-retval.sh
parentf126f6ec221ec9f8aac3f1aebf855bbc46e9b796 (diff)
downloadgit-5ad6e2b495dfb7264fc94dc548af9c0a10901683.zip
git-5ad6e2b495dfb7264fc94dc548af9c0a10901683.tar.gz
git-5ad6e2b495dfb7264fc94dc548af9c0a10901683.tar.bz2
diff: show usage for unknown builtin_diff_files() options
The git-diff command has many modes (comparing worktree to index, index to HEAD, individual blobs, etc). As a result, it dispatches to many helper functions and cannot completely parse its options until we're in those helper functions. Most of them, when seeing an unknown option, exit immediately by calling usage(). But builtin_diff_files(), which is the default if no revision or blob arguments are given, instead prints an error() and returns -1. One obvious shortcoming here is that the user doesn't get to see the usual usage message. But there's a much more important bug: the -1 return is fed to diff_result_code(), which is not ready to handle it. By default, it passes the code along as an exit code. We try to avoid negative exit codes because they get converted to unsigned values, but it should at least consistently show up as non-zero (i.e., a failure). But much worse is that when --exit-code is in effect, diff_result_code() will _ignore_ the status passed in by the caller, and instead only report on whether the diff found changes. It didn't, of course, because we never ran the diff, and the program unexpectedly exits with success! We can fix this bug by just calling usage(), like the other helpers do. Another option would of course be to teach diff_result_code() to handle this value. But as we'll see in the next few patches, it can be cleaned up even further. Let's just fix this bug directly to start with. Reported-by: Romain Chossart <romainchossart@gmail.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t4017-diff-retval.sh')
-rwxr-xr-xt/t4017-diff-retval.sh5
1 files changed, 5 insertions, 0 deletions
diff --git a/t/t4017-diff-retval.sh b/t/t4017-diff-retval.sh
index 5bc28ad..f439f46 100755
--- a/t/t4017-diff-retval.sh
+++ b/t/t4017-diff-retval.sh
@@ -138,4 +138,9 @@ test_expect_success 'check honors conflict marker length' '
git reset --hard
'
+test_expect_success 'option errors are not confused by --exit-code' '
+ test_must_fail git diff --exit-code --nonsense 2>err &&
+ grep '^usage:' err
+'
+
test_done