aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/gitignore/dir.go
diff options
context:
space:
mode:
authorArieh Schneier <15041913+AriehSchneier@users.noreply.github.com>2023-06-05 00:25:35 +1000
committerArieh Schneier <15041913+AriehSchneier@users.noreply.github.com>2023-06-05 00:25:35 +1000
commit4ed9ded8ca127922d8286be188eef87efd2c2ab9 (patch)
tree566ab1420d574ccf6114494ce82993db731c0c55 /plumbing/format/gitignore/dir.go
parent87d35b7f0e80cb30921480e7cf7498232bddee21 (diff)
downloadgo-git-4ed9ded8ca127922d8286be188eef87efd2c2ab9.tar.gz
plumbing: gitignore, Allow gitconfig to contain a gitignore relative to any user home. Fixes #578
Signed-off-by: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com>
Diffstat (limited to 'plumbing/format/gitignore/dir.go')
-rw-r--r--plumbing/format/gitignore/dir.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/plumbing/format/gitignore/dir.go b/plumbing/format/gitignore/dir.go
index bf6a1c1..3c4469a 100644
--- a/plumbing/format/gitignore/dir.go
+++ b/plumbing/format/gitignore/dir.go
@@ -5,6 +5,7 @@ import (
"bytes"
"io"
"os"
+ "os/user"
"strings"
"github.com/go-git/go-billy/v5"
@@ -27,9 +28,18 @@ const (
func readIgnoreFile(fs billy.Filesystem, path []string, ignoreFile string) (ps []Pattern, err error) {
if strings.HasPrefix(ignoreFile, "~") {
- home, err := os.UserHomeDir()
- if err == nil {
- ignoreFile = strings.Replace(ignoreFile, "~", home, 1)
+ 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)
+ }
}
}