From f8a08c8a55efbaecc8a99bf39b63d85b3d89170d Mon Sep 17 00:00:00 2001 From: Shulhan Date: Thu, 15 Jan 2026 15:54:41 +0700 Subject: lib/git: handle pattern "**/foo/**" The "**/foo/**" means accept any files as long as there is foo directory in the middle. --- lib/git/ignore_pattern.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/git/ignore_pattern.go') diff --git a/lib/git/ignore_pattern.go b/lib/git/ignore_pattern.go index 37fc7035..6097d46d 100644 --- a/lib/git/ignore_pattern.go +++ b/lib/git/ignore_pattern.go @@ -42,8 +42,11 @@ func ParseIgnorePattern(line []byte) (ign IgnorePattern) { line = line[:len(line)-1] } + var sepIdx int + // The "**/foo" pattern is equal to "foo", so we can remove the "**/". for bytes.HasPrefix(line, []byte("**/")) { + sepIdx = -1 // Flag it as zero or more directory before. line = line[3:] } if len(line) == 0 { @@ -57,9 +60,9 @@ func ParseIgnorePattern(line []byte) (ign IgnorePattern) { return ign } - // Get the index of directory separator, before we replace it some - // special characters with regex. - var sepIdx = bytes.LastIndexByte(line, '/') + if sepIdx == 0 { + sepIdx = bytes.LastIndexByte(line, '/') + } var RE_EVERYTHING_INSIDE = []byte(`/(.*)`) var RE_FILE_OR_DIR = []byte(`/?$`) -- cgit v1.3