From 3ae5d4de35e76f2f573b550d93bb2aed8137f1cb Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Mon, 19 Jun 2017 10:26:03 +0200 Subject: plumbing: gitignore, upgrade to go-billy.v3 and test with gocheck --- plumbing/format/gitignore/dir.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'plumbing/format/gitignore/dir.go') diff --git a/plumbing/format/gitignore/dir.go b/plumbing/format/gitignore/dir.go index 16e4617..c3bfc53 100644 --- a/plumbing/format/gitignore/dir.go +++ b/plumbing/format/gitignore/dir.go @@ -2,9 +2,10 @@ package gitignore import ( "io/ioutil" + "os" "strings" - "gopkg.in/src-d/go-billy.v2" + "gopkg.in/src-d/go-billy.v3" ) const ( @@ -17,8 +18,10 @@ const ( // ReadPatterns reads 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) { - if f, err := fs.Open(fs.Join(append(path, gitignoreFile)...)); err == nil { + f, err := fs.Open(fs.Join(append(path, gitignoreFile)...)) + if err == nil { defer f.Close() + if data, err := ioutil.ReadAll(f); err == nil { for _, s := range strings.Split(string(data), eol) { if !strings.HasPrefix(s, commentPrefix) && len(strings.TrimSpace(s)) > 0 { @@ -26,13 +29,16 @@ func ReadPatterns(fs billy.Filesystem, path []string) (ps []Pattern, err error) } } } + } else if !os.IsNotExist(err) { + return nil, err } - var fis []billy.FileInfo + var fis []os.FileInfo fis, err = fs.ReadDir(fs.Join(path...)) if err != nil { return } + for _, fi := range fis { if fi.IsDir() && fi.Name() != gitDir { var subps []Pattern @@ -40,6 +46,7 @@ func ReadPatterns(fs billy.Filesystem, path []string) (ps []Pattern, err error) if err != nil { return } + if len(subps) > 0 { ps = append(ps, subps...) } -- cgit