From 0cb3b64057894f0fff8634f1fdb3049d28fc0596 Mon Sep 17 00:00:00 2001 From: domi <152265924+niekdomi@users.noreply.github.com> Date: Fri, 3 Apr 2026 19:00:58 +0200 Subject: [PATCH 1/5] allow `yaml` as config file extension `yaml` is actually the preferred file extension, see: https://web.archive.org/web/20210311073506/https://yaml.org/faq.html or https://stackoverflow.com/a/22268973 Though I kept `yml` as default to prevent potential breaking changes --- pkg/config/app_config.go | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 038d6c11785..8a970cbf413 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -92,7 +92,7 @@ func NewAppConfig( }) } else { // Load default config files - path := filepath.Join(configDir, ConfigFilename) + _, path := findFirstConfigFile(ConfigFilenames, configDir) configFile := &ConfigFile{Path: path, Policy: ConfigFilePolicyCreateIfMissing} configFiles = []*ConfigFile{configFile} } @@ -125,7 +125,7 @@ func NewAppConfig( } func ConfigDir() string { - _, filePath := findConfigFile(ConfigFilename) + _, filePath := findFirstConfigFile(ConfigFilenames, xdg.ConfigHome+"/lazygit") return filepath.Dir(filePath) } @@ -583,36 +583,26 @@ func (c *AppConfig) GetTempDir() string { return c.tempDir } -// findConfigFile looks for a possibly existing config file. -// This function does NOT create any folders or files. -func findConfigFile(filename string) (exists bool, path string) { - if envConfigDir := os.Getenv("CONFIG_DIR"); envConfigDir != "" { - return true, filepath.Join(envConfigDir, filename) - } - - // look for jesseduffield/lazygit/filename in XDG_CONFIG_HOME and XDG_CONFIG_DIRS - legacyConfigPath, err := xdg.SearchConfigFile(filepath.Join("jesseduffield", "lazygit", filename)) - if err == nil { - return true, legacyConfigPath - } - - // look for lazygit/filename in XDG_CONFIG_HOME and XDG_CONFIG_DIRS - configFilepath, err := xdg.SearchConfigFile(filepath.Join("lazygit", filename)) - if err == nil { - return true, configFilepath +// findFirstConfigFile returns the first existing file in dir from the list, or +// the default path if none exist. +func findFirstConfigFile(filenames []string, dir string) (exists bool, path string) { + for _, filename := range filenames { + fullPath := filepath.Join(dir, filename) + if _, err := os.Stat(fullPath); err == nil { + return true, fullPath + } } - - return false, filepath.Join(xdg.ConfigHome, "lazygit", filename) + return false, filepath.Join(dir, filenames[0]) } -var ConfigFilename = "config.yml" +var ConfigFilenames = []string{"config.yml", "config.yaml"} // stateFilePath looks for a possibly existing state file. // if none exist, the default path is returned and all parent directories are created. func stateFilePath(filename string) (string, error) { - exists, legacyStateFile := findConfigFile(filename) - if exists { - return legacyStateFile, nil + _, path := findFirstConfigFile([]string{filename}, xdg.ConfigHome+"/lazygit") + if _, err := os.Stat(path); err == nil { + return path, nil } // looks for XDG_STATE_HOME/lazygit/filename From d355716a6ad9cce07da883dcaa10b9b37f8200b6 Mon Sep 17 00:00:00 2001 From: domi <152265924+niekdomi@users.noreply.github.com> Date: Fri, 3 Apr 2026 20:24:53 +0200 Subject: [PATCH 2/5] make it non breaking --- pkg/config/app_config.go | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 8a970cbf413..89570eedd26 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -92,7 +92,7 @@ func NewAppConfig( }) } else { // Load default config files - _, path := findFirstConfigFile(ConfigFilenames, configDir) + _, path := findConfigFile(ConfigFilenames) configFile := &ConfigFile{Path: path, Policy: ConfigFilePolicyCreateIfMissing} configFiles = []*ConfigFile{configFile} } @@ -125,7 +125,7 @@ func NewAppConfig( } func ConfigDir() string { - _, filePath := findFirstConfigFile(ConfigFilenames, xdg.ConfigHome+"/lazygit") + _, filePath := findConfigFile(ConfigFilenames) return filepath.Dir(filePath) } @@ -583,6 +583,32 @@ func (c *AppConfig) GetTempDir() string { return c.tempDir } +// findConfigFile looks for a possibly existing config file. +// This function does NOT create any folders or files. +func findConfigFile(filenames []string) (exists bool, path string) { + if envConfigDir := os.Getenv("CONFIG_DIR"); envConfigDir != "" { + return findFirstConfigFile(filenames, envConfigDir) + } + + // look for jesseduffield/lazygit/ in XDG_CONFIG_HOME and XDG_CONFIG_DIRS + for _, filename := range filenames { + legacyConfigPath, err := xdg.SearchConfigFile(filepath.Join("jesseduffield", "lazygit", filename)) + if err == nil { + return true, legacyConfigPath + } + } + + // look for lazygit/ in XDG_CONFIG_HOME and XDG_CONFIG_DIRS + for _, filename := range filenames { + configFilepath, err := xdg.SearchConfigFile(filepath.Join("lazygit", filename)) + if err == nil { + return true, configFilepath + } + } + + return false, filepath.Join(xdg.ConfigHome, "lazygit", filenames[0]) +} + // findFirstConfigFile returns the first existing file in dir from the list, or // the default path if none exist. func findFirstConfigFile(filenames []string, dir string) (exists bool, path string) { @@ -600,9 +626,9 @@ var ConfigFilenames = []string{"config.yml", "config.yaml"} // stateFilePath looks for a possibly existing state file. // if none exist, the default path is returned and all parent directories are created. func stateFilePath(filename string) (string, error) { - _, path := findFirstConfigFile([]string{filename}, xdg.ConfigHome+"/lazygit") - if _, err := os.Stat(path); err == nil { - return path, nil + exists, legacyStateFile := findConfigFile([]string{filename}) + if exists { + return legacyStateFile, nil } // looks for XDG_STATE_HOME/lazygit/filename From d355a057de308a0d2e12959268defd308008c937 Mon Sep 17 00:00:00 2001 From: domi <152265924+niekdomi@users.noreply.github.com> Date: Fri, 3 Apr 2026 20:27:21 +0200 Subject: [PATCH 3/5] . --- pkg/config/app_config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 89570eedd26..5d374e4110c 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -590,7 +590,7 @@ func findConfigFile(filenames []string) (exists bool, path string) { return findFirstConfigFile(filenames, envConfigDir) } - // look for jesseduffield/lazygit/ in XDG_CONFIG_HOME and XDG_CONFIG_DIRS + // look for jesseduffield/lazygit/filename in XDG_CONFIG_HOME and XDG_CONFIG_DIRS for _, filename := range filenames { legacyConfigPath, err := xdg.SearchConfigFile(filepath.Join("jesseduffield", "lazygit", filename)) if err == nil { From 20ada1b9f30c8937016bfebd0b5c90e06c59155e Mon Sep 17 00:00:00 2001 From: domi <152265924+niekdomi@users.noreply.github.com> Date: Fri, 3 Apr 2026 20:43:21 +0200 Subject: [PATCH 4/5] make test work --- pkg/config/app_config.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 5d374e4110c..0e8ec2f5401 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -626,9 +626,9 @@ var ConfigFilenames = []string{"config.yml", "config.yaml"} // stateFilePath looks for a possibly existing state file. // if none exist, the default path is returned and all parent directories are created. func stateFilePath(filename string) (string, error) { - exists, legacyStateFile := findConfigFile([]string{filename}) - if exists { - return legacyStateFile, nil + _, path := findFirstConfigFile([]string{filename}, xdg.ConfigHome+"/lazygit") + if _, err := os.Stat(path); err == nil { + return path, nil } // looks for XDG_STATE_HOME/lazygit/filename From b60dc3720c7e118b2858092cddbe52256ae8ec02 Mon Sep 17 00:00:00 2001 From: domi <152265924+niekdomi@users.noreply.github.com> Date: Fri, 3 Apr 2026 20:44:51 +0200 Subject: [PATCH 5/5] . --- pkg/config/app_config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 0e8ec2f5401..7e76e1adbcd 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -598,7 +598,7 @@ func findConfigFile(filenames []string) (exists bool, path string) { } } - // look for lazygit/ in XDG_CONFIG_HOME and XDG_CONFIG_DIRS + // look for lazygit/filename in XDG_CONFIG_HOME and XDG_CONFIG_DIRS for _, filename := range filenames { configFilepath, err := xdg.SearchConfigFile(filepath.Join("lazygit", filename)) if err == nil {