aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/gitignore/dir.go
diff options
context:
space:
mode:
Diffstat (limited to 'plumbing/format/gitignore/dir.go')
-rw-r--r--plumbing/format/gitignore/dir.go13
1 files changed, 10 insertions, 3 deletions
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...)
}