mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 12:25:47 +02:00
Support per-repo config files
For now we only support .git/lazygit.yml; in the future we would also like to support ./.lazygit.yml, but that one will need a trust prompt as it could be versioned, which adds quite a bit of complexity, so we leave that for later. We do, however, support config files in parent directories (all the way up to the root directory). This makes it possible to add a config file that applies to multiple repos at once. Useful if you want to set different options for all your work repos vs. all your open-source repos, for instance.
This commit is contained in:
parent
d6d48f2866
commit
74ed1ac584
2 changed files with 95 additions and 25 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
@ -307,6 +308,16 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, contextKey types.Context
|
|||
return err
|
||||
}
|
||||
|
||||
err = gui.Config.ReloadUserConfigForRepo(gui.getPerRepoConfigFiles())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = gui.onUserConfigLoaded()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
contextToPush := gui.resetState(startArgs)
|
||||
|
||||
gui.resetHelpersAndControllers()
|
||||
|
@ -342,6 +353,39 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, contextKey types.Context
|
|||
return nil
|
||||
}
|
||||
|
||||
func (gui *Gui) getPerRepoConfigFiles() []*config.ConfigFile {
|
||||
repoConfigFiles := []*config.ConfigFile{
|
||||
// TODO: add filepath.Join(gui.git.RepoPaths.RepoPath(), ".lazygit.yml"),
|
||||
// with trust prompt
|
||||
{
|
||||
Path: filepath.Join(gui.git.RepoPaths.RepoGitDirPath(), "lazygit.yml"),
|
||||
Policy: config.ConfigFilePolicySkipIfMissing,
|
||||
},
|
||||
}
|
||||
|
||||
prevDir := gui.c.Git().RepoPaths.RepoPath()
|
||||
dir := filepath.Dir(prevDir)
|
||||
for dir != prevDir {
|
||||
repoConfigFiles = utils.Prepend(repoConfigFiles, &config.ConfigFile{
|
||||
Path: filepath.Join(dir, ".lazygit.yml"),
|
||||
Policy: config.ConfigFilePolicySkipIfMissing,
|
||||
})
|
||||
prevDir = dir
|
||||
dir = filepath.Dir(dir)
|
||||
}
|
||||
return repoConfigFiles
|
||||
}
|
||||
|
||||
func (gui *Gui) onUserConfigLoaded() error {
|
||||
userConfig := gui.Config.GetUserConfig()
|
||||
gui.Common.SetUserConfig(userConfig)
|
||||
|
||||
gui.setColorScheme()
|
||||
gui.configureViewProperties()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// resetState reuses the repo state from our repo state map, if the repo was
|
||||
// open before; otherwise it creates a new one.
|
||||
func (gui *Gui) resetState(startArgs appTypes.StartArgs) types.Context {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue