From 5dad9b23030e344a4fd1458df0c50e6ada55a01a Mon Sep 17 00:00:00 2001 From: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com> Date: Sun, 9 Jul 2023 17:08:04 +1000 Subject: *: Handle paths starting with ~username Signed-off-by: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com> --- plumbing/format/gitignore/dir.go | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'plumbing/format/gitignore/dir.go') 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 { -- cgit