Skip to content

Commit 3da165c

Browse files
committed
Merge branch 'mt/checkout-index-corner-cases'
The error codepath around the "--temp/--prefix" feature of "git checkout-index" has been improved. * mt/checkout-index-corner-cases: checkout-index: omit entries with no tempname from --temp output write_entry(): fix misuses of `path` in error messages
2 parents f47c332 + 3f7ba60 commit 3da165c

File tree

3 files changed

+51
-15
lines changed

3 files changed

+51
-15
lines changed

builtin/checkout-index.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,35 @@ static struct checkout state = CHECKOUT_INIT;
2323
static void write_tempfile_record(const char *name, const char *prefix)
2424
{
2525
int i;
26+
int have_tempname = 0;
2627

2728
if (CHECKOUT_ALL == checkout_stage) {
28-
for (i = 1; i < 4; i++) {
29-
if (i > 1)
30-
putchar(' ');
31-
if (topath[i][0])
32-
fputs(topath[i], stdout);
33-
else
34-
putchar('.');
29+
for (i = 1; i < 4; i++)
30+
if (topath[i][0]) {
31+
have_tempname = 1;
32+
break;
33+
}
34+
35+
if (have_tempname) {
36+
for (i = 1; i < 4; i++) {
37+
if (i > 1)
38+
putchar(' ');
39+
if (topath[i][0])
40+
fputs(topath[i], stdout);
41+
else
42+
putchar('.');
43+
}
3544
}
36-
} else
45+
} else if (topath[checkout_stage][0]) {
46+
have_tempname = 1;
3747
fputs(topath[checkout_stage], stdout);
48+
}
3849

39-
putchar('\t');
40-
write_name_quoted_relative(name, prefix, stdout,
41-
nul_term_line ? '\0' : '\n');
50+
if (have_tempname) {
51+
putchar('\t');
52+
write_name_quoted_relative(name, prefix, stdout,
53+
nul_term_line ? '\0' : '\n');
54+
}
4255

4356
for (i = 0; i < 4; i++) {
4457
topath[i][0] = 0;

entry.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static int write_entry(struct cache_entry *ce,
282282
new_blob = read_blob_entry(ce, &size);
283283
if (!new_blob)
284284
return error("unable to read sha1 file of %s (%s)",
285-
path, oid_to_hex(&ce->oid));
285+
ce->name, oid_to_hex(&ce->oid));
286286

287287
/*
288288
* We can't make a real symlink; write out a regular file entry
@@ -309,7 +309,7 @@ static int write_entry(struct cache_entry *ce,
309309
new_blob = read_blob_entry(ce, &size);
310310
if (!new_blob)
311311
return error("unable to read sha1 file of %s (%s)",
312-
path, oid_to_hex(&ce->oid));
312+
ce->name, oid_to_hex(&ce->oid));
313313
}
314314

315315
/*
@@ -354,7 +354,7 @@ static int write_entry(struct cache_entry *ce,
354354

355355
case S_IFGITLINK:
356356
if (to_tempfile)
357-
return error("cannot create temporary submodule %s", path);
357+
return error("cannot create temporary submodule %s", ce->name);
358358
if (mkdir(path, 0777) < 0)
359359
return error("cannot create submodule directory %s", path);
360360
sub = submodule_from_ce(ce);
@@ -365,7 +365,7 @@ static int write_entry(struct cache_entry *ce,
365365
break;
366366

367367
default:
368-
return error("unknown file mode for %s in index", path);
368+
return error("unknown file mode for %s in index", ce->name);
369369
}
370370

371371
finish:

t/t2006-checkout-index-basic.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,27 @@ test_expect_success 'checkout-index reports errors (stdin)' '
3232
test_i18ngrep not.in.the.cache stderr
3333
'
3434

35+
test_expect_success 'checkout-index --temp correctly reports error on missing blobs' '
36+
test_when_finished git reset --hard &&
37+
missing_blob=$(echo "no such blob here" | git hash-object --stdin) &&
38+
cat >objs <<-EOF &&
39+
100644 $missing_blob file
40+
120000 $missing_blob symlink
41+
EOF
42+
git update-index --index-info <objs &&
43+
44+
test_must_fail git checkout-index --temp symlink file 2>stderr &&
45+
test_i18ngrep "unable to read sha1 file of file ($missing_blob)" stderr &&
46+
test_i18ngrep "unable to read sha1 file of symlink ($missing_blob)" stderr
47+
'
48+
49+
test_expect_success 'checkout-index --temp correctly reports error for submodules' '
50+
git init sub &&
51+
test_commit -C sub file &&
52+
git submodule add ./sub &&
53+
git commit -m sub &&
54+
test_must_fail git checkout-index --temp sub 2>stderr &&
55+
test_i18ngrep "cannot create temporary submodule sub" stderr
56+
'
57+
3558
test_done

0 commit comments

Comments
 (0)