Skip to content

Commit

Permalink
Support "\" in non-wildcard exclusion entries
Browse files Browse the repository at this point in the history
"\" 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 <finnag@pvv.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Finn Arne Gangstad authored and Junio C Hamano committed Feb 12, 2009
1 parent ab2fdb3 commit dd482ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ int match_pathspec(const char **pathspec, const char *name, int namelen, int pre

static int no_wildcard(const char *string)
{
return string[strcspn(string, "*?[{")] == '\0';
return string[strcspn(string, "*?[{\\")] == '\0';
}

void add_exclude(const char *string, const char *base,
Expand Down
9 changes: 8 additions & 1 deletion t/t3001-ls-files-others-exclude.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ do
>$dir/a.$i
done
done
>"#ignore1"
>"#ignore2"
>"#hidden"

cat >expect <<EOF
a.2
Expand All @@ -42,6 +45,9 @@ three/a.8
EOF

echo '.gitignore
\#ignore1
\#ignore2*
\#hid*n
output
expect
.gitignore
Expand Down Expand Up @@ -79,9 +85,10 @@ test_expect_success \
>output &&
test_cmp expect output'

cat > excludes-file << EOF
cat > excludes-file <<\EOF
*.[1-8]
e*
\#*
EOF

git config core.excludesFile excludes-file
Expand Down

0 comments on commit dd482ee

Please sign in to comment.