aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/gitignore/dir.go
diff options
context:
space:
mode:
authorPaulo Gomes <pjbgf@linux.com>2023-06-04 23:07:11 +0100
committerGitHub <noreply@github.com>2023-06-04 23:07:11 +0100
commitdd067af60e33a9aaf156186eeb143816e0748335 (patch)
tree566ab1420d574ccf6114494ce82993db731c0c55 /plumbing/format/gitignore/dir.go
parent87d35b7f0e80cb30921480e7cf7498232bddee21 (diff)
parent4ed9ded8ca127922d8286be188eef87efd2c2ab9 (diff)
downloadgo-git-dd067af60e33a9aaf156186eeb143816e0748335.tar.gz
Merge pull request #785 from AriehSchneier/gitignore-relative-any-user
plumbing: gitignore, Allow gitconfig to contain a gitignore relative to any user home. Fixes #578
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)
+ }
}
}