diff --git a/tools/ignorefiles/gitignore.go b/tools/ignorefiles/gitignore.go index b6beb0d47..5377429b9 100644 --- a/tools/ignorefiles/gitignore.go +++ b/tools/ignorefiles/gitignore.go @@ -273,11 +273,17 @@ func get_global_gitconfig_excludesfile() (ans string) { line := strings.TrimSpace(s.Text()) if in_core { if strings.HasPrefix(line, "[") { - in_core = false + in_core = line == "[core]" continue } if k, rest, found := strings.Cut(line, "="); found && strings.ToLower(strings.TrimSpace(k)) == `excludesfile` { ans = strings.TrimSpace(rest) + ans = utils.Expanduser(ans) + if !filepath.IsAbs(ans) { + if a, err := filepath.Abs(ans); err != nil { + ans = a + } + } } } else if strings.ToLower(line) == "[core]" { in_core = true diff --git a/tools/ignorefiles/gitignore_test.go b/tools/ignorefiles/gitignore_test.go index b5a03944b..0b4dc1065 100644 --- a/tools/ignorefiles/gitignore_test.go +++ b/tools/ignorefiles/gitignore_test.go @@ -3,6 +3,7 @@ package ignorefiles import ( "fmt" "io/fs" + "os" "strings" "testing" @@ -142,4 +143,19 @@ bar `: { } } } + os.WriteFile(utils.Expanduser("~/.gitconfig"), []byte(` + [core] + something + [else] + ... + [core] + ... + [core] + excludesfile = one + [core] + excludesfile = ~/global-gitignore +`), 0600) + if ef := get_global_gitconfig_excludesfile(); ef != utils.Expanduser("~/global-gitignore") { + t.Fatalf("global gitconfig excludes file incorrect: %s != %s", utils.Expanduser("~/global-gitignore"), ef) + } }