Skip to content

Commit b8f5288

Browse files
committed
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 30eaf67 commit b8f5288

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
@@ -273,7 +273,7 @@ void apply_virtualfilesystem(struct index_state *istate)
273273
if (buf[i - 1] == '/') {
274274
if (ignore_case)
275275
adjust_dirname_case(istate, entry);
276-
pos = index_name_pos(istate, entry, len - 1);
276+
pos = index_name_pos(istate, entry, len);
277277
if (pos < 0) {
278278
pos = -pos - 1;
279279
while (pos < istate->cache_nr && !fspathncmp(istate->cache[pos]->name, entry, len)) {

0 commit comments

Comments
 (0)