aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/gitignore/dir.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-06-19 10:26:03 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-06-19 10:26:03 +0200
commit3ae5d4de35e76f2f573b550d93bb2aed8137f1cb (patch)
treeab3c103c09dd6eaf07c99de04b643869eca1a7ce /plumbing/format/gitignore/dir.go
parent93633b5767b0d571bedc724364209d30f96a7b17 (diff)
downloadgo-git-3ae5d4de35e76f2f573b550d93bb2aed8137f1cb.tar.gz
plumbing: gitignore, upgrade to go-billy.v3 and test with gocheck
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...)
}