aboutsummaryrefslogtreecommitdiff
path: root/lib/git/ignore_pattern.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-01-15 15:54:41 +0700
committerShulhan <ms@kilabit.info>2026-01-15 17:22:25 +0700
commitf8a08c8a55efbaecc8a99bf39b63d85b3d89170d (patch)
tree4fe187befc7146751fcba617d6dd655cdc4c4268 /lib/git/ignore_pattern.go
parent83aa06572a833823a233ae3834282bdb0be524e5 (diff)
downloadpakakeh.go-f8a08c8a55efbaecc8a99bf39b63d85b3d89170d.tar.xz
lib/git: handle pattern "**/foo/**"
The "**/foo/**" means accept any files as long as there is foo directory in the middle.
Diffstat (limited to 'lib/git/ignore_pattern.go')
-rw-r--r--lib/git/ignore_pattern.go9
1 files changed, 6 insertions, 3 deletions
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(`/?$`)