Skip to content

Commit c01c8d3

Browse files
committed
update-index (bugfix): --cacheinfo should block directories
Add explicit check for directory entry mode, throwing an error if found. Without the check, sparse directory cache entries could be added to any index (including non-sparse). In a sparse index, this would at least cause inconsistencies in the cache tree; for a non-sparse index, such an entry being present at all is a bug. Signed-off-by: Victoria Dye <[email protected]>
1 parent f28fc01 commit c01c8d3

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

builtin/update-index.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ static int add_cacheinfo(unsigned int mode, const struct object_id *oid,
411411
if (!verify_path(path, mode))
412412
return error("Invalid path '%s'", path);
413413

414+
if (S_ISSPARSEDIR(mode))
415+
return error("%s: cannot add directory as cache entry", path);
416+
414417
len = strlen(path);
415418
ce = make_empty_cache_entry(&the_index, len);
416419

t/t2107-update-index-basic.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ test_expect_success '--cacheinfo mode,sha1,path (new syntax)' '
6464
test_cmp expect actual
6565
'
6666

67+
test_expect_success '--cacheinfo does not accept directory mode' '
68+
mkdir folder1 &&
69+
echo content >folder1/content &&
70+
git add folder1 &&
71+
folder1_oid=$(git ls-files -s folder1 | git hash-object --stdin) &&
72+
test_must_fail git update-index --add --cacheinfo 040000 $folder1_oid folder1/
73+
'
74+
6775
test_expect_success '.lock files cleaned up' '
6876
mkdir cleanup &&
6977
(

0 commit comments

Comments
 (0)