Skip to content

Commit b99bb74

Browse files
jamillderrickstolee
authored andcommitted
vfs: fix case where directories not handled correctly
The vfs does not correctly handle the case when there is a file that begins with the same prefix as a directory. For example, the following setup would encounter this issue: A directory contains a file named `dir1.sln` and a directory named `dir1/`. The directory `dir1` contains other files. The directory `dir1` is in the virtual file system list The contents of `dir1` should be in the virtual file system, but it is not. The contents of this directory do not have the skip worktree bit cleared as expected. The problem is in the `apply_virtualfilesystem(...)` function where it does not include the trailing slash of the directory name when looking up the position in the index to start clearing the skip worktree bit. This fix is it include the trailing slash when finding the first index entry from `index_name_pos(...)`.
1 parent 1a38880 commit b99bb74

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

t/t1092-virtualfilesystem.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,4 +348,23 @@ test_expect_success 'on folder renamed' '
348348
test_cmp expected actual
349349
'
350350

351+
test_expect_success 'folder with same prefix as file' '
352+
clean_repo &&
353+
touch dir1.sln &&
354+
write_script .git/hooks/virtualfilesystem <<-\EOF &&
355+
printf "dir1/\0"
356+
printf "dir1.sln\0"
357+
EOF
358+
git add dir1.sln &&
359+
git ls-files -v > actual &&
360+
cat > expected <<-\EOF &&
361+
H dir1.sln
362+
H dir1/file1.txt
363+
H dir1/file2.txt
364+
S dir2/file1.txt
365+
S dir2/file2.txt
366+
EOF
367+
test_cmp expected actual
368+
'
369+
351370
test_done

virtualfilesystem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ void apply_virtualfilesystem(struct index_state *istate)
277277
if (buf[i - 1] == '/') {
278278
if (ignore_case)
279279
adjust_dirname_case(istate, entry);
280-
pos = index_name_pos(istate, entry, len - 1);
280+
pos = index_name_pos(istate, entry, len);
281281
if (pos < 0) {
282282
pos = -pos - 1;
283283
while (pos < istate->cache_nr && !fspathncmp(istate->cache[pos]->name, entry, len)) {

0 commit comments

Comments
 (0)