Skip to content

Commit a3ea4d7

Browse files
pcloudsgitster
authored andcommitted
exclude: fix a bug in prefix compare optimization
When "namelen" becomes zero at this stage, we have matched the fixed part, but whether it actually matches the pattern still depends on the pattern in "exclude". As demonstrated in t3001, path "three/a.3" exists and it matches the "three/a.3" part in pattern "three/a.3[abc]", but that does not mean a true match. Don't be too optimistic and let fnmatch() do the job. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 593cb88 commit a3ea4d7

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ int excluded_from_list(const char *pathname,
585585
namelen -= prefix;
586586
}
587587

588-
if (!namelen || !fnmatch_icase(exclude, name, FNM_PATHNAME))
588+
if (!fnmatch_icase(exclude, name, FNM_PATHNAME))
589589
return to_exclude;
590590
}
591591
return -1; /* undecided */

t/t3001-ls-files-others-exclude.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,10 @@ test_expect_success 'subdirectory ignore (l1)' '
214214
test_cmp expect actual
215215
'
216216

217+
test_expect_success 'pattern matches prefix completely' '
218+
: >expect &&
219+
git ls-files -i -o --exclude "/three/a.3[abc]" >actual &&
220+
test_cmp expect actual
221+
'
222+
217223
test_done

0 commit comments

Comments
 (0)