aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/gitignore
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2021-05-02 23:33:16 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2021-05-02 23:33:16 +0200
commitc69d5331743e49d3672897cf1c552e5e123d4509 (patch)
treedf503db7e8889cef313641b31808fc7404b400e3 /plumbing/format/gitignore
parent67d34902b0c41ee5d6d283f4c5b6c2ad7db123fd (diff)
downloadgo-git-c69d5331743e49d3672897cf1c552e5e123d4509.tar.gz
plumbing: format, use os.UserHomeDir()
Diffstat (limited to 'plumbing/format/gitignore')
-rw-r--r--plumbing/format/gitignore/dir.go5
-rw-r--r--plumbing/format/gitignore/dir_test.go27
2 files changed, 15 insertions, 17 deletions
diff --git a/plumbing/format/gitignore/dir.go b/plumbing/format/gitignore/dir.go
index 922c458..7cea50c 100644
--- a/plumbing/format/gitignore/dir.go
+++ b/plumbing/format/gitignore/dir.go
@@ -5,7 +5,6 @@ import (
"bytes"
"io/ioutil"
"os"
- "os/user"
"strings"
"github.com/go-git/go-billy/v5"
@@ -116,12 +115,12 @@ func loadPatterns(fs billy.Filesystem, path string) (ps []Pattern, err error) {
//
// The function assumes fs is rooted at the root filesystem.
func LoadGlobalPatterns(fs billy.Filesystem) (ps []Pattern, 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 gitignore patterns from from the gitignore file
diff --git a/plumbing/format/gitignore/dir_test.go b/plumbing/format/gitignore/dir_test.go
index a3e7ba6..94ed7be 100644
--- a/plumbing/format/gitignore/dir_test.go
+++ b/plumbing/format/gitignore/dir_test.go
@@ -2,7 +2,6 @@ package gitignore
import (
"os"
- "os/user"
"strconv"
"github.com/go-git/go-billy/v5"
@@ -55,23 +54,23 @@ func (s *MatcherSuite) SetUpTest(c *C) {
s.GFS = fs
// setup root that contains user home
- usr, err := user.Current()
+ home, err := os.UserHomeDir()
c.Assert(err, IsNil)
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(" excludesfile = " + strconv.Quote(fs.Join(usr.HomeDir, ".gitignore_global")) + "\n"))
+ _, err = f.Write([]byte(" excludesfile = " + strconv.Quote(fs.Join(home, ".gitignore_global")) + "\n"))
c.Assert(err, IsNil)
err = f.Close()
c.Assert(err, IsNil)
- f, err = fs.Create(fs.Join(usr.HomeDir, ".gitignore_global"))
+ f, err = fs.Create(fs.Join(home, ".gitignore_global"))
c.Assert(err, IsNil)
_, err = f.Write([]byte("# IntelliJ\n"))
c.Assert(err, IsNil)
@@ -86,10 +85,10 @@ func (s *MatcherSuite) SetUpTest(c *C) {
// root that contains user home, but missing ~/.gitconfig
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, ".gitignore_global"))
+ f, err = fs.Create(fs.Join(home, ".gitignore_global"))
c.Assert(err, IsNil)
_, err = f.Write([]byte("# IntelliJ\n"))
c.Assert(err, IsNil)
@@ -104,17 +103,17 @@ func (s *MatcherSuite) SetUpTest(c *C) {
// setup root that contains user home, but missing excludesfile 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)
- f, err = fs.Create(fs.Join(usr.HomeDir, ".gitignore_global"))
+ f, err = fs.Create(fs.Join(home, ".gitignore_global"))
c.Assert(err, IsNil)
_, err = f.Write([]byte("# IntelliJ\n"))
c.Assert(err, IsNil)
@@ -129,14 +128,14 @@ func (s *MatcherSuite) SetUpTest(c *C) {
// setup root that contains user home, but missing .gitnignore
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(" excludesfile = " + strconv.Quote(fs.Join(usr.HomeDir, ".gitignore_global")) + "\n"))
+ _, err = f.Write([]byte(" excludesfile = " + strconv.Quote(fs.Join(home, ".gitignore_global")) + "\n"))
c.Assert(err, IsNil)
err = f.Close()
c.Assert(err, IsNil)