mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-16 13:34:48 +02:00
Dont write to ~/.gitconfig in the tests
Just in case the tests are run without setting HOME
This commit is contained in:
@@ -261,11 +261,15 @@ func CompileGitIgnoreLine(line string) (ans GitPattern, skipped_line bool) {
|
||||
}
|
||||
|
||||
func get_global_gitconfig_excludesfile() (ans string) {
|
||||
return _get_global_gitconfig_excludesfile(utils.Expanduser("~/.gitconfig"))
|
||||
}
|
||||
|
||||
func _get_global_gitconfig_excludesfile(home_gitconfig string) (ans string) {
|
||||
cfhome := os.Getenv("XDG_CONFIG_HOME")
|
||||
if cfhome == "" {
|
||||
cfhome = utils.Expanduser("~/.config")
|
||||
}
|
||||
for _, candidate := range []string{"/etc/gitconfig", filepath.Join(cfhome, "git", "config"), utils.Expanduser("~/.gitconfig")} {
|
||||
for _, candidate := range []string{"/etc/gitconfig", filepath.Join(cfhome, "git", "config"), home_gitconfig} {
|
||||
if data, err := os.ReadFile(candidate); err == nil {
|
||||
s := utils.NewLineScanner(utils.UnsafeBytesToString(data))
|
||||
in_core := false
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -143,19 +144,21 @@ bar `: {
|
||||
}
|
||||
}
|
||||
}
|
||||
os.WriteFile(utils.Expanduser("~/.gitconfig"), []byte(`
|
||||
[core]
|
||||
something
|
||||
[else]
|
||||
...
|
||||
[core]
|
||||
...
|
||||
[core]
|
||||
excludesfile = one
|
||||
[core]
|
||||
excludesfile = ~/global-gitignore
|
||||
tdir := t.TempDir()
|
||||
gc := filepath.Join(tdir, ".gitconfig")
|
||||
os.WriteFile(gc, []byte(`
|
||||
[core]
|
||||
something
|
||||
[else]
|
||||
...
|
||||
[core]
|
||||
...
|
||||
[core]
|
||||
excludesfile = one
|
||||
[core]
|
||||
excludesfile = ~/global-gitignore
|
||||
`), 0600)
|
||||
if ef := get_global_gitconfig_excludesfile(); ef != utils.Expanduser("~/global-gitignore") {
|
||||
if ef := _get_global_gitconfig_excludesfile(gc); ef != utils.Expanduser("~/global-gitignore") {
|
||||
t.Fatalf("global gitconfig excludes file incorrect: %s != %s", utils.Expanduser("~/global-gitignore"), ef)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user