aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format
diff options
context:
space:
mode:
Diffstat (limited to 'plumbing/format')
-rw-r--r--plumbing/format/config/option.go2
-rw-r--r--plumbing/format/config/section.go2
-rw-r--r--plumbing/format/gitignore/dir.go12
-rw-r--r--plumbing/format/gitignore/dir_test.go18
4 files changed, 21 insertions, 13 deletions
diff --git a/plumbing/format/config/option.go b/plumbing/format/config/option.go
index d4775e4..218f992 100644
--- a/plumbing/format/config/option.go
+++ b/plumbing/format/config/option.go
@@ -19,7 +19,7 @@ type Options []*Option
// IsKey returns true if the given key matches
// this option's key in a case-insensitive comparison.
func (o *Option) IsKey(key string) bool {
- return strings.ToLower(o.Key) == strings.ToLower(key)
+ return strings.EqualFold(o.Key, key)
}
func (opts Options) GoString() string {
diff --git a/plumbing/format/config/section.go b/plumbing/format/config/section.go
index 4a17e3b..f743da6 100644
--- a/plumbing/format/config/section.go
+++ b/plumbing/format/config/section.go
@@ -61,7 +61,7 @@ func (s Subsections) GoString() string {
// IsName checks if the name provided is equals to the Section name, case insensitive.
func (s *Section) IsName(name string) bool {
- return strings.ToLower(s.Name) == strings.ToLower(name)
+ return strings.EqualFold(s.Name, name)
}
// Option return the value for the specified key. Empty string is returned if
diff --git a/plumbing/format/gitignore/dir.go b/plumbing/format/gitignore/dir.go
index f4444bf..4a26325 100644
--- a/plumbing/format/gitignore/dir.go
+++ b/plumbing/format/gitignore/dir.go
@@ -1,6 +1,7 @@
package gitignore
import (
+ "bufio"
"bytes"
"io/ioutil"
"os"
@@ -15,7 +16,6 @@ import (
const (
commentPrefix = "#"
coreSection = "core"
- eol = "\n"
excludesfile = "excludesfile"
gitDir = ".git"
gitignoreFile = ".gitignore"
@@ -29,11 +29,11 @@ func readIgnoreFile(fs billy.Filesystem, path []string, ignoreFile string) (ps [
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 {
- ps = append(ps, ParsePattern(s, path))
- }
+ scanner := bufio.NewScanner(f)
+ for scanner.Scan() {
+ s := scanner.Text()
+ if !strings.HasPrefix(s, commentPrefix) && len(strings.TrimSpace(s)) > 0 {
+ ps = append(ps, ParsePattern(s, path))
}
}
} else if !os.IsNotExist(err) {
diff --git a/plumbing/format/gitignore/dir_test.go b/plumbing/format/gitignore/dir_test.go
index c0301f7..a3e7ba6 100644
--- a/plumbing/format/gitignore/dir_test.go
+++ b/plumbing/format/gitignore/dir_test.go
@@ -15,7 +15,7 @@ type MatcherSuite struct {
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
- MIFS billy.Filesystem // root that contains user home, but missing .gitnignore
+ MIFS billy.Filesystem // root that contains user home, but missing .gitignore
SFS billy.Filesystem // root that contains /etc/gitconfig
}
@@ -29,6 +29,8 @@ func (s *MatcherSuite) SetUpTest(c *C) {
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)
@@ -41,9 +43,14 @@ func (s *MatcherSuite) SetUpTest(c *C) {
err = f.Close()
c.Assert(err, IsNil)
- fs.MkdirAll("another", os.ModePerm)
- fs.MkdirAll("vendor/github.com", os.ModePerm)
- fs.MkdirAll("vendor/gopkg.in", os.ModePerm)
+ 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
@@ -167,9 +174,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, 2)
+ 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)
}