Make **/ in an exclude pattern match zero directories #367

Merged
clawbot merged 1 commits from issue-338-double-star-exclude into next 2026-10-14 00:13:28 +02:00
Collaborator

Fixes #338.

What was wrong: the glob library behind exclude patterns needs a slash on both sides of **. So the anchored pattern /**/x missed an x directly under the snapshot path, and a/**/*.log missed a/x.log. gitignore matches both, and the config init template says ** is supported.

What changed (compileExcludePatterns in internal/snapshot/scanner.go):

  • A leading **/ now makes any pattern match at every depth, anchored or not. /**/x is treated like **/x, which was already matched unanchored as plain x.
  • A pattern holding /**/ is compiled once for every way of keeping each /**/ or making it a single /. Any of those globs matching excludes the path.

Each case has a test.

What the diff does not show: the library's own {a,b} alternatives looked like the obvious fix (a{/,/**/}b), but with ** inside them in the middle of a pattern they miss paths they should match. That is why the pattern is compiled more than once instead.

Judgement call: the test for a/**/b uses a/**/*.log. With a plain name after the **, the library already matched a/b, because its prefix-and-suffix shortcut lets the two slashes overlap. A glob in the last part avoids that shortcut, so the test fails without the fix.

Model: opus-5-5

Fixes https://git.eeqj.de/sneak/vaultik/issues/338. **What was wrong:** the glob library behind exclude patterns needs a slash on both sides of `**`. So the anchored pattern `/**/x` missed an `x` directly under the snapshot path, and `a/**/*.log` missed `a/x.log`. gitignore matches both, and the `config init` template says `**` is supported. **What changed** (`compileExcludePatterns` in `internal/snapshot/scanner.go`): - A leading `**/` now makes any pattern match at every depth, anchored or not. `/**/x` is treated like `**/x`, which was already matched unanchored as plain `x`. - A pattern holding `/**/` is compiled once for every way of keeping each `/**/` or making it a single `/`. Any of those globs matching excludes the path. Each case has a test. **What the diff does not show:** the library's own `{a,b}` alternatives looked like the obvious fix (`a{/,/**/}b`), but with `**` inside them in the middle of a pattern they miss paths they should match. That is why the pattern is compiled more than once instead. Judgement call: the test for `a/**/b` uses `a/**/*.log`. With a plain name after the `**`, the library already matched `a/b`, because its prefix-and-suffix shortcut lets the two slashes overlap. A glob in the last part avoids that shortcut, so the test fails without the fix. Model: opus-5-5
clawbot added the needs-review label 2026-10-13 19:47:09 +02:00
clawbot self-assigned this 2026-10-13 19:47:09 +02:00
Author
Collaborator
  • internal/snapshot/scanner.go line 2036: the new comment's example, that a/**/b misses a/b, is false. With a plain name after the **, the glob library already matched a/b before this change, as the PR body itself says. A reader who tries the example sees it match and may decide the extra patterns compiled below are not needed. Acceptable: use an example that really failed, such as a/**/*.log missing a/x.log (the case the test uses).

Model: opus-5-5

- `internal/snapshot/scanner.go` line 2036: the new comment's example, that `a/**/b` misses `a/b`, is false. With a plain name after the `**`, the glob library already matched `a/b` before this change, as the PR body itself says. A reader who tries the example sees it match and may decide the extra patterns compiled below are not needed. Acceptable: use an example that really failed, such as `a/**/*.log` missing `a/x.log` (the case the test uses). Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-13 21:20:17 +02:00
clawbot force-pushed issue-338-double-star-exclude from 82a5df4688 to 42a3c738fa 2026-10-13 21:21:59 +02:00 Compare
clawbot force-pushed issue-338-double-star-exclude from 42a3c738fa to b0642d2763 2026-10-13 22:08:38 +02:00 Compare
clawbot force-pushed issue-338-double-star-exclude from b0642d2763 to cc69561b3e 2026-10-13 22:55:07 +02:00 Compare
clawbot added 1 commit 2026-10-13 23:54:02 +02:00
The glob library needs a slash on both sides of **, so the anchored
pattern /**/x missed an x directly under the snapshot path, and
a/**/*.log missed a/x.log. As in gitignore, a leading **/ now makes any
pattern, anchored or not, match at every depth, and a pattern holding
/**/ is also compiled with each /**/ made a single slash. The library's
{a,b} alternatives cannot express this: with ** inside them in
mid-pattern they miss paths they should match.

Judgement call: the test for a/**/b uses a/**/*.log, because with a
plain name after the ** the glob library already matched a/b.

Model: opus-5-5
clawbot force-pushed issue-338-double-star-exclude from cc69561b3e to 1723961380 2026-10-13 23:54:02 +02:00 Compare
Author
Collaborator

Rework:

  • internal/snapshot/scanner.go: the comment now uses a/**/*.log missing a/x.log as its example, a case that really failed before the fix.
  • Rebased onto current next.

Model: opus-5-5

Rework: - `internal/snapshot/scanner.go`: the comment now uses `a/**/*.log` missing `a/x.log` as its example, a case that really failed before the fix. - Rebased onto current `next`. Model: opus-5-5
clawbot added needs-review and removed needs-rework labels 2026-10-13 23:54:10 +02:00
Author
Collaborator

Review passed.

Model: opus-5-5

Review passed. Model: opus-5-5
clawbot merged commit abad8161bc into next 2026-10-14 00:13:28 +02:00
clawbot deleted branch issue-338-double-star-exclude 2026-10-14 00:13:28 +02:00
Sign in to join this conversation.