From 55b186dc6178ad9c47821aeb684073dbf6893ed3 Mon Sep 17 00:00:00 2001 From: enisdenjo Date: Wed, 27 Oct 2021 22:57:41 +0200 Subject: plumbing: gitignore, Read .git/info/exclude file too. --- plumbing/format/gitignore/dir_test.go | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'plumbing/format/gitignore/dir_test.go') diff --git a/plumbing/format/gitignore/dir_test.go b/plumbing/format/gitignore/dir_test.go index 94ed7be..f2cf7a8 100644 --- a/plumbing/format/gitignore/dir_test.go +++ b/plumbing/format/gitignore/dir_test.go @@ -11,6 +11,7 @@ import ( type MatcherSuite struct { GFS billy.Filesystem // git repository root + IEFS billy.Filesystem // git repository root using info/exclude instead RFS billy.Filesystem // root that contains user home MCFS billy.Filesystem // root that contains user home, but missing ~/.gitconfig MEFS billy.Filesystem // root that contains user home, but missing excludesfile entry @@ -53,6 +54,39 @@ func (s *MatcherSuite) SetUpTest(c *C) { s.GFS = fs + // setup generic git repository root using info/exclude instead + fs = memfs.New() + err = fs.MkdirAll(".git/info", os.ModePerm) + c.Assert(err, IsNil) + f, err = fs.Create(".git/info/exclude") + c.Assert(err, IsNil) + _, err = f.Write([]byte("vendor/g*/\n")) + c.Assert(err, IsNil) + _, err = f.Write([]byte("ignore.crlf\r\n")) + c.Assert(err, IsNil) + err = f.Close() + c.Assert(err, IsNil) + + err = fs.MkdirAll("vendor", os.ModePerm) + c.Assert(err, IsNil) + f, err = fs.Create("vendor/.gitignore") + c.Assert(err, IsNil) + _, err = f.Write([]byte("!github.com/\n")) + c.Assert(err, IsNil) + err = f.Close() + c.Assert(err, IsNil) + + err = fs.MkdirAll("another", os.ModePerm) + c.Assert(err, IsNil) + err = fs.MkdirAll("ignore.crlf", os.ModePerm) + c.Assert(err, IsNil) + err = fs.MkdirAll("vendor/github.com", os.ModePerm) + c.Assert(err, IsNil) + err = fs.MkdirAll("vendor/gopkg.in", os.ModePerm) + c.Assert(err, IsNil) + + s.IEFS = fs + // setup root that contains user home home, err := os.UserHomeDir() c.Assert(err, IsNil) @@ -179,6 +213,15 @@ func (s *MatcherSuite) TestDir_ReadPatterns(c *C) { 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{"vendor", "github.com"}, true), Equals, false) + + ps, err = ReadPatterns(s.IEFS, nil) + c.Assert(err, IsNil) + c.Assert(ps, HasLen, 3) + + m = NewMatcher(ps) + 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{"vendor", "github.com"}, true), Equals, false) } func (s *MatcherSuite) TestDir_LoadGlobalPatterns(c *C) { -- cgit From 92c37d55cc818cd8dda9cc04eff80da154f9aa39 Mon Sep 17 00:00:00 2001 From: enisdenjo Date: Wed, 27 Oct 2021 23:09:07 +0200 Subject: better tests --- plumbing/format/gitignore/dir_test.go | 48 +++++++---------------------------- 1 file changed, 9 insertions(+), 39 deletions(-) (limited to 'plumbing/format/gitignore/dir_test.go') diff --git a/plumbing/format/gitignore/dir_test.go b/plumbing/format/gitignore/dir_test.go index f2cf7a8..facc36d 100644 --- a/plumbing/format/gitignore/dir_test.go +++ b/plumbing/format/gitignore/dir_test.go @@ -11,7 +11,6 @@ import ( type MatcherSuite struct { GFS billy.Filesystem // git repository root - IEFS billy.Filesystem // git repository root using info/exclude instead RFS billy.Filesystem // root that contains user home MCFS billy.Filesystem // root that contains user home, but missing ~/.gitconfig MEFS billy.Filesystem // root that contains user home, but missing excludesfile entry @@ -25,40 +24,17 @@ var _ = Suite(&MatcherSuite{}) func (s *MatcherSuite) SetUpTest(c *C) { // setup generic git repository root fs := memfs.New() - f, err := fs.Create(".gitignore") - c.Assert(err, IsNil) - _, err = f.Write([]byte("vendor/g*/\n")) - c.Assert(err, IsNil) - _, err = f.Write([]byte("ignore.crlf\r\n")) - c.Assert(err, IsNil) - err = f.Close() - c.Assert(err, IsNil) - err = fs.MkdirAll("vendor", os.ModePerm) + err := fs.MkdirAll(".git/info", os.ModePerm) c.Assert(err, IsNil) - f, err = fs.Create("vendor/.gitignore") + f, err := fs.Create(".git/info/exclude") c.Assert(err, IsNil) - _, err = f.Write([]byte("!github.com/\n")) + _, err = f.Write([]byte("exclude.crlf\r\n")) c.Assert(err, IsNil) err = f.Close() c.Assert(err, IsNil) - err = fs.MkdirAll("another", os.ModePerm) - c.Assert(err, IsNil) - err = fs.MkdirAll("ignore.crlf", os.ModePerm) - c.Assert(err, IsNil) - err = fs.MkdirAll("vendor/github.com", os.ModePerm) - c.Assert(err, IsNil) - err = fs.MkdirAll("vendor/gopkg.in", os.ModePerm) - c.Assert(err, IsNil) - - s.GFS = fs - - // setup generic git repository root using info/exclude instead - fs = memfs.New() - err = fs.MkdirAll(".git/info", os.ModePerm) - c.Assert(err, IsNil) - f, err = fs.Create(".git/info/exclude") + f, err = fs.Create(".gitignore") c.Assert(err, IsNil) _, err = f.Write([]byte("vendor/g*/\n")) c.Assert(err, IsNil) @@ -78,6 +54,8 @@ func (s *MatcherSuite) SetUpTest(c *C) { err = fs.MkdirAll("another", os.ModePerm) c.Assert(err, IsNil) + err = fs.MkdirAll("exclude.crlf", os.ModePerm) + c.Assert(err, IsNil) err = fs.MkdirAll("ignore.crlf", os.ModePerm) c.Assert(err, IsNil) err = fs.MkdirAll("vendor/github.com", os.ModePerm) @@ -85,7 +63,7 @@ func (s *MatcherSuite) SetUpTest(c *C) { err = fs.MkdirAll("vendor/gopkg.in", os.ModePerm) c.Assert(err, IsNil) - s.IEFS = fs + s.GFS = fs // setup root that contains user home home, err := os.UserHomeDir() @@ -207,18 +185,10 @@ func (s *MatcherSuite) SetUpTest(c *C) { func (s *MatcherSuite) TestDir_ReadPatterns(c *C) { ps, err := ReadPatterns(s.GFS, nil) c.Assert(err, IsNil) - c.Assert(ps, HasLen, 3) + c.Assert(ps, HasLen, 4) m := NewMatcher(ps) - 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{"vendor", "github.com"}, true), Equals, false) - - ps, err = ReadPatterns(s.IEFS, nil) - c.Assert(err, IsNil) - c.Assert(ps, HasLen, 3) - - 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{"vendor", "github.com"}, true), Equals, false) -- cgit