diff options
author | Jeff King <peff@peff.net> | 2020-10-27 10:37:14 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-10-27 22:41:56 +0300 |
commit | 7e41061588eab25d0c015e79aa8d04956bee482a (patch) | |
tree | f3f81e76dd35c59a34e3126c1305c809e5bc971e /builtin/checkout-index.c | |
parent | 0b809c82480a870f4a46fa66f0eddc1c1b04cf6b (diff) |
checkout-index: propagate errors to exit code
If we encounter an error while checking out an explicit path, we print a
message to stderr but do not actually exit with a non-zero code. While
this is a plumbing command and the behavior goes all the way back to
33db5f4d90 (Add a "checkout-cache" command which does what the name
suggests., 2005-04-09), this is almost certainly an oversight:
- we _do_ return an exit code from checkout_file(); the caller just
never reads it
- errors while checking out all paths (with "-a") do result in a
non-zero exit code.
- it would be quite unusual not to use the exit code for an error,
as otherwise the caller has no idea the command failed except by
scraping stderr
To keep our tests simple and portable, we can use the most obvious
error: asking to checkout a path which is not in the index at all.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/checkout-index.c')
-rw-r--r-- | builtin/checkout-index.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c index 195165d8bd..4bbfc92dce 100644 --- a/builtin/checkout-index.c +++ b/builtin/checkout-index.c @@ -167,6 +167,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) int prefix_length; int force = 0, quiet = 0, not_new = 0; int index_opt = 0; + int err = 0; struct option builtin_checkout_index_options[] = { OPT_BOOL('a', "all", &all, N_("check out all files in the index")), @@ -231,7 +232,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) if (read_from_stdin) die("git checkout-index: don't mix '--stdin' and explicit filenames"); p = prefix_path(prefix, prefix_length, arg); - checkout_file(p, prefix); + err |= checkout_file(p, prefix); free(p); } @@ -253,13 +254,16 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) strbuf_swap(&buf, &unquoted); } p = prefix_path(prefix, prefix_length, buf.buf); - checkout_file(p, prefix); + err |= checkout_file(p, prefix); free(p); } strbuf_release(&unquoted); strbuf_release(&buf); } + if (err) + return 1; + if (all) checkout_all(prefix, prefix_length); |