Fix escaping of glob special characters in pathspecs
authorKevin Ballard <kevin@sb.org>
Wed, 13 Aug 2008 22:34:34 +0000 (15:34 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 14 Aug 2008 00:11:03 +0000 (17:11 -0700)
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>
dir.c
t/t3700-add.sh
diff --git a/dir.c b/dir.c
index 29d1d5ba31def46ba8b55905dc60773cc6cc167e..109e05b01346ac13296dfbcfa2355a43d97731cd 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -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 == '\\';
 }
 
 /*
index e83fa1f6894dd13eb11cae6afb8ecbd3dcb999db..fcbc203e71cff29de6268e26ff680fef9837bd34 100755 (executable)
@@ -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