aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2021-11-01 22:47:16 +0100
committerGitHub <noreply@github.com>2021-11-01 22:47:16 +0100
commit934e99b85109874d8a24f344786c30276715bde0 (patch)
treefc0f630079b26eb116e4f7401b779d904236fe92 /plumbing
parent8884a203d3798a9bc50f54e98582cb5758b4f5ee (diff)
parent92c37d55cc818cd8dda9cc04eff80da154f9aa39 (diff)
downloadgo-git-934e99b85109874d8a24f344786c30276715bde0.tar.gz
Merge pull request #402 from enisdenjo/gitdir-info-exclude
plumbing: gitignore, Read .git/info/exclude file too.
Diffstat (limited to 'plumbing')
-rw-r--r--plumbing/format/gitignore/dir.go25
-rw-r--r--plumbing/format/gitignore/dir_test.go17
2 files changed, 30 insertions, 12 deletions
diff --git a/plumbing/format/gitignore/dir.go b/plumbing/format/gitignore/dir.go
index 7cea50c..15bc9c7 100644
--- a/plumbing/format/gitignore/dir.go
+++ b/plumbing/format/gitignore/dir.go
@@ -13,13 +13,14 @@ import (
)
const (
- commentPrefix = "#"
- coreSection = "core"
- excludesfile = "excludesfile"
- gitDir = ".git"
- gitignoreFile = ".gitignore"
- gitconfigFile = ".gitconfig"
- systemFile = "/etc/gitconfig"
+ commentPrefix = "#"
+ coreSection = "core"
+ excludesfile = "excludesfile"
+ gitDir = ".git"
+ gitignoreFile = ".gitignore"
+ gitconfigFile = ".gitconfig"
+ systemFile = "/etc/gitconfig"
+ infoExcludeFile = gitDir + "/info/exclude"
)
// readIgnoreFile reads a specific git ignore file.
@@ -42,10 +43,14 @@ func readIgnoreFile(fs billy.Filesystem, path []string, ignoreFile string) (ps [
return
}
-// ReadPatterns reads gitignore patterns recursively traversing through the directory
-// structure. The result is in the ascending order of priority (last higher).
+// ReadPatterns reads the .git/info/exclude and then the gitignore patterns
+// recursively traversing through the directory structure. The result is in
+// the ascending order of priority (last higher).
func ReadPatterns(fs billy.Filesystem, path []string) (ps []Pattern, err error) {
- ps, _ = readIgnoreFile(fs, path, gitignoreFile)
+ ps, _ = readIgnoreFile(fs, path, infoExcludeFile)
+
+ subps, _ := readIgnoreFile(fs, path, gitignoreFile)
+ ps = append(ps, subps...)
var fis []os.FileInfo
fis, err = fs.ReadDir(fs.Join(path...))
diff --git a/plumbing/format/gitignore/dir_test.go b/plumbing/format/gitignore/dir_test.go
index 94ed7be..facc36d 100644
--- a/plumbing/format/gitignore/dir_test.go
+++ b/plumbing/format/gitignore/dir_test.go
@@ -24,7 +24,17 @@ var _ = Suite(&MatcherSuite{})
func (s *MatcherSuite) SetUpTest(c *C) {
// setup generic git repository root
fs := memfs.New()
- f, err := fs.Create(".gitignore")
+
+ 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("exclude.crlf\r\n"))
+ c.Assert(err, IsNil)
+ err = f.Close()
+ c.Assert(err, IsNil)
+
+ f, err = fs.Create(".gitignore")
c.Assert(err, IsNil)
_, err = f.Write([]byte("vendor/g*/\n"))
c.Assert(err, IsNil)
@@ -44,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)
@@ -173,9 +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{"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)