Merge branch 'jk/checkout-index-errors'

"git checkout-index" did not consistently signal an error with its
exit status.

* jk/checkout-index-errors:
  checkout-index: propagate errors to exit code
  checkout-index: drop error message from empty --stage=all
This commit is contained in:
Junio C Hamano 2020-11-09 14:06:26 -08:00
Родитель 65681e75c1 7e41061588
Коммит 92d6bd2e90
3 изменённых файлов: 34 добавлений и 3 удалений

Просмотреть файл

@ -79,6 +79,14 @@ static int checkout_file(const char *name, const char *prefix)
return errs > 0 ? -1 : 0;
}
/*
* At this point we know we didn't try to check anything out. If it was
* because we did find an entry but it was stage 0, that's not an
* error.
*/
if (has_same_name && checkout_stage == CHECKOUT_ALL)
return 0;
if (!state.quiet) {
fprintf(stderr, "git checkout-index: %s ", name);
if (!has_same_name)
@ -159,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")),
@ -223,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);
}
@ -245,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);

Просмотреть файл

@ -88,9 +88,17 @@ test_expect_success 'checkout all stage 2 to temporary files' '
done
'
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 &&
test_i18ngrep not.in.the.cache stderr
'
test_expect_success 'checkout all stages/one file to nothing' '
rm -f path* .merge_* actual &&
git checkout-index --stage=all --temp -- path0 >actual &&
git checkout-index --stage=all --temp -- path0 >actual 2>stderr &&
test_must_be_empty stderr &&
test_line_count = 0 actual
'

Просмотреть файл

@ -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