git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Fix escaping of glob special characters in pathspecs

From
Kevin Ballard <kevin@sb.org>
Date
Aug 13, 2008, 22:34 UTC
Message-ID
<1218666874-85937-1-git-send-email-kevin@sb.org>

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>
---
 dir.c          |    2 +-
 t/t3700-add.sh |    8 ++++++++
 2 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/dir.c b/dir.c
index 29d1d5b..109e05b 100644
--- 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 == '\\';
 }
 
 /*
diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index 7d123d1..77a782c 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -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
-- 
1.6.0.rc3.1.g9002abb
Message 1 of 1 in “Fix escaping of glob special characters in pathspecs”
  1. Fix escaping of glob special characters in pathspecsKevin Ballard, Aug 13, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.