diff options
author | Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com> | 2023-07-09 17:08:04 +1000 |
---|---|---|
committer | Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com> | 2023-07-09 17:08:04 +1000 |
commit | 5dad9b23030e344a4fd1458df0c50e6ada55a01a (patch) | |
tree | 3049fbf24af25a3e52bf7a391e959e837e032e3a /plumbing/format/gitignore | |
parent | dc17aae6503560777a665c9cfb0d2fcb3a9a9274 (diff) | |
download | go-git-5dad9b23030e344a4fd1458df0c50e6ada55a01a.tar.gz |
*: Handle paths starting with ~username
Signed-off-by: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com>
Diffstat (limited to 'plumbing/format/gitignore')
-rw-r--r-- | plumbing/format/gitignore/dir.go | 18 |
1 files changed, 2 insertions, 16 deletions
diff --git a/plumbing/format/gitignore/dir.go b/plumbing/format/gitignore/dir.go index 3c4469a..d8fb30c 100644 --- a/plumbing/format/gitignore/dir.go +++ b/plumbing/format/gitignore/dir.go @@ -5,10 +5,10 @@ import ( "bytes" "io" "os" - "os/user" "strings" "github.com/go-git/go-billy/v5" + "github.com/go-git/go-git/v5/internal/path_util" "github.com/go-git/go-git/v5/plumbing/format/config" gioutil "github.com/go-git/go-git/v5/utils/ioutil" ) @@ -27,21 +27,7 @@ const ( // readIgnoreFile reads a specific git ignore file. func readIgnoreFile(fs billy.Filesystem, path []string, ignoreFile string) (ps []Pattern, err error) { - if strings.HasPrefix(ignoreFile, "~") { - firstSlash := strings.Index(ignoreFile, "/") - if firstSlash == 1 { - home, err := os.UserHomeDir() - if err == nil { - ignoreFile = strings.Replace(ignoreFile, "~", home, 1) - } - } else if firstSlash > 1 { - username := ignoreFile[1:firstSlash] - userAccount, err := user.Lookup(username) - if err == nil { - ignoreFile = strings.Replace(ignoreFile, ignoreFile[:firstSlash], userAccount.HomeDir, 1) - } - } - } + ignoreFile, _ = path_util.ReplaceTildeWithHome(ignoreFile) f, err := fs.Open(fs.Join(append(path, ignoreFile)...)) if err == nil { |