Skip to content

Commit ea335b5

Browse files
lilyballgitster
authored andcommitted
Fix escaping of glob special characters in pathspecs
match_one implements an optimized pathspec match where it only uses fnmatch if it detects glob special characters in the pattern. Unfortunately it didn't treat \ as a special character, so attempts to escape a glob special character would fail even though fnmatch() supports it. Signed-off-by: Kevin Ballard <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9612e74 commit ea335b5

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int common_prefix(const char **pathspec)
5454

5555
static inline int special_char(unsigned char c1)
5656
{
57-
return !c1 || c1 == '*' || c1 == '[' || c1 == '?';
57+
return !c1 || c1 == '*' || c1 == '[' || c1 == '?' || c1 == '\\';
5858
}
5959

6060
/*

t/t3700-add.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,12 @@ test_expect_success 'git add (add.ignore-errors = false)' '
222222
! ( git ls-files foo1 | grep foo1 )
223223
'
224224

225+
test_expect_success 'git add '\''fo\?bar'\'' ignores foobar' '
226+
git reset --hard &&
227+
touch fo\?bar foobar &&
228+
git add '\''fo\?bar'\'' &&
229+
git ls-files fo\?bar | grep -F fo\?bar &&
230+
! ( git ls-files foobar | grep foobar )
231+
'
232+
225233
test_done

0 commit comments

Comments
 (0)