aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2025-07-09 19:52:07 +0200
committerJakob Unterwurzacher2025-07-09 19:52:07 +0200
commita2efa0e5113b0efc96cac9618dd8d438310b417f (patch)
treeae6ca1819c59df12a491bc108b7df9dddfdde1c7
parentd98fe5e4922a409b367a1e0eeec138e7ae598452 (diff)
go-git-gitignore: simpleNameMatch: bail out on "p.dirOnly && !isDir"
Fixes this test failure: --- FAIL: TestIssue927Minimal (0.03s) exclude_test.go:44: File "dir/zzz" is visible, but should be hidden FAIL testcases[0] = struct { plaintextnames bool; deterministic_names bool }{plaintextnames:true, deterministic_names:false} failed exit status 1 FAIL github.com/rfjakob/gocryptfs/v2/tests/reverse 0.577s
-rw-r--r--internal/go-git-gitignore/pattern.go7
-rw-r--r--internal/go-git-gitignore/pattern_test.go6
2 files changed, 10 insertions, 3 deletions
diff --git a/internal/go-git-gitignore/pattern.go b/internal/go-git-gitignore/pattern.go
index c80e841..94d585f 100644
--- a/internal/go-git-gitignore/pattern.go
+++ b/internal/go-git-gitignore/pattern.go
@@ -90,6 +90,13 @@ func (p *pattern) Match(path []string, isDir bool) MatchResult {
}
func (p *pattern) simpleNameMatch(path []string, isDir bool) bool {
+ // gocryptfs patch: simple fix for https://github.com/go-git/go-git/issues/1596
+ // gocryptfs can get away with this because each parent directory has already been checked
+ // separately on LOOKUP.
+ if p.dirOnly && !isDir {
+ return false
+ }
+
for i, name := range path {
if match, err := filepath.Match(p.pattern[0], name); err != nil {
return false
diff --git a/internal/go-git-gitignore/pattern_test.go b/internal/go-git-gitignore/pattern_test.go
index 17aa16a..a6f4eb1 100644
--- a/internal/go-git-gitignore/pattern_test.go
+++ b/internal/go-git-gitignore/pattern_test.go
@@ -41,7 +41,7 @@ func (s *PatternSuite) TestMatch_domainMismatch_mismatch() {
func (s *PatternSuite) TestSimpleMatch_withDomain() {
p := ParsePattern("middle/", []string{"value", "volcano"})
r := p.Match([]string{"value", "volcano", "middle", "tail"}, false)
- s.Equal(Exclude, r)
+ s.Equal(NoMatch, r)
}
func (s *PatternSuite) TestSimpleMatch_onlyMatchInDomain_mismatch() {
@@ -71,13 +71,13 @@ func (s *PatternSuite) TestSimpleMatch_atEnd() {
func (s *PatternSuite) TestSimpleMatch_atStart_dirWanted() {
p := ParsePattern("value/", nil)
r := p.Match([]string{"value", "tail"}, false)
- s.Equal(Exclude, r)
+ s.Equal(NoMatch, r)
}
func (s *PatternSuite) TestSimpleMatch_inTheMiddle_dirWanted() {
p := ParsePattern("value/", nil)
r := p.Match([]string{"head", "value", "tail"}, false)
- s.Equal(Exclude, r)
+ s.Equal(NoMatch, r)
}
func (s *PatternSuite) TestSimpleMatch_atEnd_dirWanted() {