Skip to content

Commit 568a40b

Browse files
jamilljeffhostetler
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 c436012 commit 568a40b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

t/t1093-virtualfilesystem.sh

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

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