Skip to content

Commit dd482ee

Browse files
Finn Arne Gangstadgitster
authored andcommitted
Support "\" in non-wildcard exclusion entries
"\" was treated differently in exclude rules depending on whether a wildcard match was done. For wildcard rules, "\" was de-escaped in fnmatch, but this was not done for other rules since they used strcmp instead. A file named "#foo" would not be excluded by "\#foo", but would be excluded by "\#foo*". We now treat all rules with "\" as wildcard rules. Another solution could be to de-escape all non-wildcard rules as we read them, but we would have to do the de-escaping exactly as fnmatch does it to avoid inconsistencies. Signed-off-by: Finn Arne Gangstad <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ab2fdb3 commit dd482ee

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ int match_pathspec(const char **pathspec, const char *name, int namelen, int pre
139139

140140
static int no_wildcard(const char *string)
141141
{
142-
return string[strcspn(string, "*?[{")] == '\0';
142+
return string[strcspn(string, "*?[{\\")] == '\0';
143143
}
144144

145145
void add_exclude(const char *string, const char *base,

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ do
1919
>$dir/a.$i
2020
done
2121
done
22+
>"#ignore1"
23+
>"#ignore2"
24+
>"#hidden"
2225

2326
cat >expect <<EOF
2427
a.2
@@ -42,6 +45,9 @@ three/a.8
4245
EOF
4346

4447
echo '.gitignore
48+
\#ignore1
49+
\#ignore2*
50+
\#hid*n
4551
output
4652
expect
4753
.gitignore
@@ -79,9 +85,10 @@ test_expect_success \
7985
>output &&
8086
test_cmp expect output'
8187

82-
cat > excludes-file << EOF
88+
cat > excludes-file <<\EOF
8389
*.[1-8]
8490
e*
91+
\#*
8592
EOF
8693

8794
git config core.excludesFile excludes-file

0 commit comments

Comments
 (0)