Make a leading **/ in an exclude pattern match at the top level (closes #303)
check / check (push) Waiting to run
check / check (push) Waiting to run
An unanchored exclude pattern such as **/node_modules or **/*.pyc needed a / before the name, so it excluded sub/node_modules and sub/y.pyc but backed up node_modules/ and x.pyc directly under the snapshot path. An unanchored pattern already matches at every depth, so the leading **/ is now dropped when the pattern is compiled and, as in gitignore, the pattern matches the top level too. Judgement call: an anchored /**/x is left as it was; the issue covers patterns that start with **/. Model: opus-5-5
This commit is contained in:
@@ -22,6 +22,15 @@ the tag exists and is exercised; what is left is merging `next` to
|
||||
|
||||
# Completed Steps
|
||||
|
||||
- 2026-10-13: Made an exclude pattern starting with `**/` also match
|
||||
directly under the snapshot path
|
||||
([issue #303](https://git.eeqj.de/sneak/vaultik/issues/303)).
|
||||
`**/node_modules` and `**/*.pyc`, the patterns `config.example.yml`
|
||||
uses, excluded `sub/node_modules` and `sub/y.pyc` but backed up
|
||||
`node_modules/` and `x.pyc` at the top of the path, since the pattern
|
||||
required a `/` before the name. As in gitignore, such a pattern now
|
||||
matches at every depth, the top included.
|
||||
|
||||
- 2026-10-12: Bound the local index to the destination an `s3.*` config
|
||||
names ([issue #298](https://git.eeqj.de/sneak/vaultik/issues/298)).
|
||||
Only `storage_url` was checked, so after `s3.bucket` or `s3.prefix`
|
||||
|
||||
@@ -531,3 +531,50 @@ func TestExcludePatterns_UnanchoredPatternFile(t *testing.T) {
|
||||
require.Equal(t, 1, result.FilesScanned,
|
||||
"Unanchored pattern for file should match anywhere")
|
||||
}
|
||||
|
||||
func TestExcludePatterns_DoubleStarDirectoryAtEveryDepth(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// As in gitignore, a leading **/ also matches directly under the source dir
|
||||
fs := setupAnchoredTestFS(t)
|
||||
|
||||
scanner, repos, cleanup := createTestScanner(t, fs, []string{"**/projectname"})
|
||||
defer cleanup()
|
||||
|
||||
ctx := context.Background()
|
||||
createSnapshotRecord(ctx, t, repos, "test-snapshot")
|
||||
|
||||
result, err := scanner.Scan(ctx, "/backup", "test-snapshot")
|
||||
require.NoError(t, err)
|
||||
|
||||
// **/projectname should exclude BOTH:
|
||||
// - /backup/projectname/file.txt
|
||||
// - /backup/otherproject/projectname/file.txt
|
||||
// Total files: 4, excluded: 2
|
||||
require.Equal(t, 2, result.FilesScanned,
|
||||
"**/ directory pattern should match at the top level and nested")
|
||||
}
|
||||
|
||||
func TestExcludePatterns_DoubleStarFileAtEveryDepth(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// As in gitignore, a leading **/ also matches directly under the source dir
|
||||
fs := setupAnchoredTestFS(t)
|
||||
|
||||
scanner, repos, cleanup := createTestScanner(t, fs, []string{"**/*.txt"})
|
||||
defer cleanup()
|
||||
|
||||
ctx := context.Background()
|
||||
createSnapshotRecord(ctx, t, repos, "test-snapshot")
|
||||
|
||||
result, err := scanner.Scan(ctx, "/backup", "test-snapshot")
|
||||
require.NoError(t, err)
|
||||
|
||||
// **/*.txt should exclude ALL .txt files:
|
||||
// - /backup/file.txt
|
||||
// - /backup/projectname/file.txt
|
||||
// - /backup/otherproject/projectname/file.txt
|
||||
// Total files: 4, excluded: 3
|
||||
require.Equal(t, 1, result.FilesScanned,
|
||||
"**/ file pattern should match at the top level and nested")
|
||||
}
|
||||
|
||||
@@ -2013,6 +2013,14 @@ func compileExcludePatterns(patterns []string) []compiledPattern {
|
||||
// Remove trailing slash if present (directory indicator)
|
||||
pattern = strings.TrimSuffix(pattern, "/")
|
||||
|
||||
// A leading "**/" demands a "/" before the name and so misses an
|
||||
// entry directly under the source path. An unanchored pattern
|
||||
// already matches at every depth, so drop the prefix: as in
|
||||
// gitignore, "**/x" then also matches a top-level "x".
|
||||
if !anchored {
|
||||
pattern = strings.TrimPrefix(pattern, "**/")
|
||||
}
|
||||
|
||||
// Compile the glob pattern
|
||||
// For patterns without path separators, we need to match them as components
|
||||
// e.g., ".git" should match ".git" anywhere in the path
|
||||
|
||||
Reference in New Issue
Block a user