Skip to content

Commit 92d6bd2

Browse files
committed
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
2 parents 65681e7 + 7e41061 commit 92d6bd2

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

builtin/checkout-index.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ static int checkout_file(const char *name, const char *prefix)
7979
return errs > 0 ? -1 : 0;
8080
}
8181

82+
/*
83+
* At this point we know we didn't try to check anything out. If it was
84+
* because we did find an entry but it was stage 0, that's not an
85+
* error.
86+
*/
87+
if (has_same_name && checkout_stage == CHECKOUT_ALL)
88+
return 0;
89+
8290
if (!state.quiet) {
8391
fprintf(stderr, "git checkout-index: %s ", name);
8492
if (!has_same_name)
@@ -159,6 +167,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
159167
int prefix_length;
160168
int force = 0, quiet = 0, not_new = 0;
161169
int index_opt = 0;
170+
int err = 0;
162171
struct option builtin_checkout_index_options[] = {
163172
OPT_BOOL('a', "all", &all,
164173
N_("check out all files in the index")),
@@ -223,7 +232,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
223232
if (read_from_stdin)
224233
die("git checkout-index: don't mix '--stdin' and explicit filenames");
225234
p = prefix_path(prefix, prefix_length, arg);
226-
checkout_file(p, prefix);
235+
err |= checkout_file(p, prefix);
227236
free(p);
228237
}
229238

@@ -245,13 +254,16 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
245254
strbuf_swap(&buf, &unquoted);
246255
}
247256
p = prefix_path(prefix, prefix_length, buf.buf);
248-
checkout_file(p, prefix);
257+
err |= checkout_file(p, prefix);
249258
free(p);
250259
}
251260
strbuf_release(&unquoted);
252261
strbuf_release(&buf);
253262
}
254263

264+
if (err)
265+
return 1;
266+
255267
if (all)
256268
checkout_all(prefix, prefix_length);
257269

t/t2004-checkout-cache-temp.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,17 @@ test_expect_success 'checkout all stage 2 to temporary files' '
8888
done
8989
'
9090

91+
test_expect_success 'checkout all stages of unknown path' '
92+
rm -f path* .merge_* actual &&
93+
test_must_fail git checkout-index --stage=all --temp \
94+
-- does-not-exist 2>stderr &&
95+
test_i18ngrep not.in.the.cache stderr
96+
'
97+
9198
test_expect_success 'checkout all stages/one file to nothing' '
9299
rm -f path* .merge_* actual &&
93-
git checkout-index --stage=all --temp -- path0 >actual &&
100+
git checkout-index --stage=all --temp -- path0 >actual 2>stderr &&
101+
test_must_be_empty stderr &&
94102
test_line_count = 0 actual
95103
'
96104

t/t2006-checkout-index-basic.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,15 @@ test_expect_success 'checkout-index -h in broken repository' '
2121
test_i18ngrep "[Uu]sage" broken/usage
2222
'
2323

24+
test_expect_success 'checkout-index reports errors (cmdline)' '
25+
test_must_fail git checkout-index -- does-not-exist 2>stderr &&
26+
test_i18ngrep not.in.the.cache stderr
27+
'
28+
29+
test_expect_success 'checkout-index reports errors (stdin)' '
30+
echo does-not-exist |
31+
test_must_fail git checkout-index --stdin 2>stderr &&
32+
test_i18ngrep not.in.the.cache stderr
33+
'
34+
2435
test_done

0 commit comments

Comments
 (0)