mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-05-13 08:26:56 +00:00
Add a test for getting the global git config excludesfile value
This commit is contained in:
parent
f742009c55
commit
ecf4ef396b
2 changed files with 23 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue