Skip to content

Commit

Permalink
Fix escaping of glob special characters in pathspecs
Browse files Browse the repository at this point in the history
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 <kevin@sb.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Kevin Ballard authored and Junio C Hamano committed Aug 14, 2008
1 parent 9612e74 commit ea335b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int common_prefix(const char **pathspec)

static inline int special_char(unsigned char c1)
{
return !c1 || c1 == '*' || c1 == '[' || c1 == '?';
return !c1 || c1 == '*' || c1 == '[' || c1 == '?' || c1 == '\\';
}

/*
Expand Down
8 changes: 8 additions & 0 deletions t/t3700-add.sh
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,12 @@ test_expect_success 'git add (add.ignore-errors = false)' '
! ( git ls-files foo1 | grep foo1 )
'

test_expect_success 'git add '\''fo\?bar'\'' ignores foobar' '
git reset --hard &&
touch fo\?bar foobar &&
git add '\''fo\?bar'\'' &&
git ls-files fo\?bar | grep -F fo\?bar &&
! ( git ls-files foobar | grep foobar )
'

test_done

0 comments on commit ea335b5

Please sign in to comment.