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); diff --git a/t/t2004-checkout-cache-temp.sh b/t/t2004-checkout-cache-temp.sh index 4308d698b9..a9352b08a8 100755 --- a/t/t2004-checkout-cache-temp.sh +++ b/t/t2004-checkout-cache-temp.sh @@ -88,7 +88,7 @@ test_expect_success 'checkout all stage 2 to temporary files' ' done ' -test_expect_failure 'checkout all stages of unknown path' ' +test_expect_success 'checkout all stages of unknown path' ' rm -f path* .merge_* actual && test_must_fail git checkout-index --stage=all --temp \ -- does-not-exist 2>stderr && diff --git a/t/t2006-checkout-index-basic.sh b/t/t2006-checkout-index-basic.sh index 57cbdfe9bc..8e181dbf01 100755 --- a/t/t2006-checkout-index-basic.sh +++ b/t/t2006-checkout-index-basic.sh @@ -21,4 +21,15 @@ test_expect_success 'checkout-index -h in broken repository' ' test_i18ngrep "[Uu]sage" broken/usage ' +test_expect_success 'checkout-index reports errors (cmdline)' ' + test_must_fail git checkout-index -- does-not-exist 2>stderr && + test_i18ngrep not.in.the.cache stderr +' + +test_expect_success 'checkout-index reports errors (stdin)' ' + echo does-not-exist | + test_must_fail git checkout-index --stdin 2>stderr && + test_i18ngrep not.in.the.cache stderr +' + test_done