aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/gitattributes
diff options
context:
space:
mode:
Diffstat (limited to 'plumbing/format/gitattributes')
-rw-r--r--plumbing/format/gitattributes/dir.go5
-rw-r--r--plumbing/format/gitattributes/dir_test.go28
2 files changed, 15 insertions, 18 deletions
diff --git a/plumbing/format/gitattributes/dir.go b/plumbing/format/gitattributes/dir.go
index b0dc82b..123fe25 100644
--- a/plumbing/format/gitattributes/dir.go
+++ b/plumbing/format/gitattributes/dir.go
@@ -2,7 +2,6 @@ package gitattributes
import (
"os"
- "os/user"
"github.com/go-git/go-billy/v5"
"github.com/go-git/go-git/v5/plumbing/format/config"
@@ -106,12 +105,12 @@ func loadPatterns(fs billy.Filesystem, path string) ([]MatchAttribute, error) {
// the function will return nil. The function assumes fs is rooted at the root
// filesystem.
func LoadGlobalPatterns(fs billy.Filesystem) (attributes []MatchAttribute, err error) {
- usr, err := user.Current()
+ home, err := os.UserHomeDir()
if err != nil {
return
}
- return loadPatterns(fs, fs.Join(usr.HomeDir, gitconfigFile))
+ return loadPatterns(fs, fs.Join(home, gitconfigFile))
}
// LoadSystemPatterns loads gitattributes patterns and attributes from the
diff --git a/plumbing/format/gitattributes/dir_test.go b/plumbing/format/gitattributes/dir_test.go
index 0ecc3b3..1b9a20d 100644
--- a/plumbing/format/gitattributes/dir_test.go
+++ b/plumbing/format/gitattributes/dir_test.go
@@ -2,7 +2,6 @@ package gitattributes
import (
"os"
- "os/user"
"strconv"
"github.com/go-git/go-billy/v5"
@@ -23,8 +22,7 @@ type MatcherSuite struct {
var _ = Suite(&MatcherSuite{})
func (s *MatcherSuite) SetUpTest(c *C) {
- // setup root that contains user home
- usr, err := user.Current()
+ home, err := os.UserHomeDir()
c.Assert(err, IsNil)
gitAttributesGlobal := func(fs billy.Filesystem, filename string) {
@@ -62,59 +60,59 @@ func (s *MatcherSuite) SetUpTest(c *C) {
fs.MkdirAll("vendor/github.com", os.ModePerm)
fs.MkdirAll("vendor/gopkg.in", os.ModePerm)
- gitAttributesGlobal(fs, fs.Join(usr.HomeDir, ".gitattributes_global"))
+ gitAttributesGlobal(fs, fs.Join(home, ".gitattributes_global"))
s.GFS = fs
fs = memfs.New()
- err = fs.MkdirAll(usr.HomeDir, os.ModePerm)
+ err = fs.MkdirAll(home, os.ModePerm)
c.Assert(err, IsNil)
- f, err = fs.Create(fs.Join(usr.HomeDir, gitconfigFile))
+ f, err = fs.Create(fs.Join(home, gitconfigFile))
c.Assert(err, IsNil)
_, err = f.Write([]byte("[core]\n"))
c.Assert(err, IsNil)
- _, err = f.Write([]byte(" attributesfile = " + strconv.Quote(fs.Join(usr.HomeDir, ".gitattributes_global")) + "\n"))
+ _, err = f.Write([]byte(" attributesfile = " + strconv.Quote(fs.Join(home, ".gitattributes_global")) + "\n"))
c.Assert(err, IsNil)
err = f.Close()
c.Assert(err, IsNil)
- gitAttributesGlobal(fs, fs.Join(usr.HomeDir, ".gitattributes_global"))
+ gitAttributesGlobal(fs, fs.Join(home, ".gitattributes_global"))
s.RFS = fs
// root that contains user home, but missing ~/.gitconfig
fs = memfs.New()
- gitAttributesGlobal(fs, fs.Join(usr.HomeDir, ".gitattributes_global"))
+ gitAttributesGlobal(fs, fs.Join(home, ".gitattributes_global"))
s.MCFS = fs
// setup root that contains user home, but missing attributesfile entry
fs = memfs.New()
- err = fs.MkdirAll(usr.HomeDir, os.ModePerm)
+ err = fs.MkdirAll(home, os.ModePerm)
c.Assert(err, IsNil)
- f, err = fs.Create(fs.Join(usr.HomeDir, gitconfigFile))
+ f, err = fs.Create(fs.Join(home, gitconfigFile))
c.Assert(err, IsNil)
_, err = f.Write([]byte("[core]\n"))
c.Assert(err, IsNil)
err = f.Close()
c.Assert(err, IsNil)
- gitAttributesGlobal(fs, fs.Join(usr.HomeDir, ".gitattributes_global"))
+ gitAttributesGlobal(fs, fs.Join(home, ".gitattributes_global"))
s.MEFS = fs
// setup root that contains user home, but missing .gitattributes
fs = memfs.New()
- err = fs.MkdirAll(usr.HomeDir, os.ModePerm)
+ err = fs.MkdirAll(home, os.ModePerm)
c.Assert(err, IsNil)
- f, err = fs.Create(fs.Join(usr.HomeDir, gitconfigFile))
+ f, err = fs.Create(fs.Join(home, gitconfigFile))
c.Assert(err, IsNil)
_, err = f.Write([]byte("[core]\n"))
c.Assert(err, IsNil)
- _, err = f.Write([]byte(" attributesfile = " + strconv.Quote(fs.Join(usr.HomeDir, ".gitattributes_global")) + "\n"))
+ _, err = f.Write([]byte(" attributesfile = " + strconv.Quote(fs.Join(home, ".gitattributes_global")) + "\n"))
c.Assert(err, IsNil)
err = f.Close()
c.Assert(err, IsNil)