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>
This commit is contained in:

committed by
Junio C Hamano

parent
0b809c8248
commit
7e41061588
@ -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
|
||||
|
Reference in New Issue
Block a user