aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaulo Gomes <pjbgf@linux.com>2024-07-13 19:49:41 +0100
committerGitHub <noreply@github.com>2024-07-13 19:49:41 +0100
commitbed3341179a776b47b2507896627960a2871fccd (patch)
tree1a09409a2e9dbcdaff6645af99e500cb65e7f9c0
parentcc1c275f825e94ce94cbc78f7215ef451a62821c (diff)
parentc127d1b355353b41e5610cc4c5c6d561e905118a (diff)
downloadgo-git-bed3341179a776b47b2507896627960a2871fccd.tar.gz
Merge pull request #1114 from BauWatch/fix-load-ignored-gitignores
plumbing: gitignore, Fix loading of ignored .gitignore files.
-rw-r--r--plumbing/format/gitignore/dir.go4
-rw-r--r--plumbing/format/gitignore/dir_test.go16
2 files changed, 19 insertions, 1 deletions
diff --git a/plumbing/format/gitignore/dir.go b/plumbing/format/gitignore/dir.go
index aca5d0d..92df5a3 100644
--- a/plumbing/format/gitignore/dir.go
+++ b/plumbing/format/gitignore/dir.go
@@ -64,6 +64,10 @@ func ReadPatterns(fs billy.Filesystem, path []string) (ps []Pattern, err error)
for _, fi := range fis {
if fi.IsDir() && fi.Name() != gitDir {
+ if NewMatcher(ps).Match(append(path, fi.Name()), true) {
+ continue
+ }
+
var subps []Pattern
subps, err = ReadPatterns(fs, append(path, fi.Name()))
if err != nil {
diff --git a/plumbing/format/gitignore/dir_test.go b/plumbing/format/gitignore/dir_test.go
index 465c571..ba8ad80 100644
--- a/plumbing/format/gitignore/dir_test.go
+++ b/plumbing/format/gitignore/dir_test.go
@@ -44,6 +44,8 @@ func (s *MatcherSuite) SetUpTest(c *C) {
c.Assert(err, IsNil)
_, err = f.Write([]byte("ignore.crlf\r\n"))
c.Assert(err, IsNil)
+ _, err = f.Write([]byte("ignore_dir\n"))
+ c.Assert(err, IsNil)
err = f.Close()
c.Assert(err, IsNil)
@@ -56,6 +58,17 @@ func (s *MatcherSuite) SetUpTest(c *C) {
err = f.Close()
c.Assert(err, IsNil)
+ err = fs.MkdirAll("ignore_dir", os.ModePerm)
+ c.Assert(err, IsNil)
+ f, err = fs.Create("ignore_dir/.gitignore")
+ c.Assert(err, IsNil)
+ _, err = f.Write([]byte("!file\n"))
+ c.Assert(err, IsNil)
+ _, err = fs.Create("ignore_dir/file")
+ c.Assert(err, IsNil)
+ err = f.Close()
+ c.Assert(err, IsNil)
+
err = fs.MkdirAll("another", os.ModePerm)
c.Assert(err, IsNil)
err = fs.MkdirAll("exclude.crlf", os.ModePerm)
@@ -267,12 +280,13 @@ func (s *MatcherSuite) SetUpTest(c *C) {
func (s *MatcherSuite) TestDir_ReadPatterns(c *C) {
checkPatterns := func(ps []Pattern) {
- c.Assert(ps, HasLen, 6)
+ c.Assert(ps, HasLen, 7)
m := NewMatcher(ps)
c.Assert(m.Match([]string{"exclude.crlf"}, true), Equals, true)
c.Assert(m.Match([]string{"ignore.crlf"}, true), Equals, true)
c.Assert(m.Match([]string{"vendor", "gopkg.in"}, true), Equals, true)
+ c.Assert(m.Match([]string{"ignore_dir", "file"}, false), Equals, true)
c.Assert(m.Match([]string{"vendor", "github.com"}, true), Equals, false)
c.Assert(m.Match([]string{"multiple", "sub", "ignores", "first", "ignore_dir"}, true), Equals, true)
c.Assert(m.Match([]string{"multiple", "sub", "ignores", "second", "ignore_dir"}, true), Equals, true)