Skip to content

Commit 9334ea8

Browse files
matheustavaresgitster
authored andcommitted
write_entry(): fix misuses of path in error messages
The variables `path` and `ce->name`, at write_entry(), usually have the same contents, but that's not the case when using a checkout prefix or writing to a tempfile. (In fact, `path` will be either empty or dirty when writing to a tempfile.) Therefore, these variables cannot be used interchangeably. In this sense, fix wrong uses of `path` in error messages where it should really be `ce->name`, and add some regression tests. (Note: there doesn't seem to be any misuse in the other way around.) Signed-off-by: Matheus Tavares <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 773e25a commit 9334ea8

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

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)