Skip to content

Commit 3e15be5

Browse files
committed
Drop the git config cache when getting focus
This allows changing git config values while lazygit is running (e.g. in a different terminal tab, or even in lazygit's ":" shell prompt), and have them take effect immediately, while still getting some benefit from caching them while lazygit is in the foreground.
1 parent f98ad65 commit 3e15be5

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

pkg/commands/git_commands/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,7 @@ func (self *ConfigCommands) GetCoreCommentChar() byte {
111111
func (self *ConfigCommands) GetRebaseUpdateRefs() bool {
112112
return self.gitConfig.GetBool("rebase.updateRefs")
113113
}
114+
115+
func (self *ConfigCommands) DropConfigCache() {
116+
self.gitConfig.DropCache()
117+
}

pkg/commands/git_config/cached_git_config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ type IGitConfig interface {
1515
GetGeneral(string) string
1616
// this is for when you want to pass 'mykey' and check if the result is truthy
1717
GetBool(string) bool
18+
19+
DropCache()
1820
}
1921

2022
type CachedGitConfig struct {
@@ -93,3 +95,10 @@ func isTruthy(value string) bool {
9395
lcValue := strings.ToLower(value)
9496
return lcValue == "true" || lcValue == "1" || lcValue == "yes" || lcValue == "on"
9597
}
98+
99+
func (self *CachedGitConfig) DropCache() {
100+
self.mutex.Lock()
101+
defer self.mutex.Unlock()
102+
103+
self.cache = make(map[string]string)
104+
}

pkg/commands/git_config/fake_git_config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ func (self *FakeGitConfig) GetGeneral(args string) string {
2727
func (self *FakeGitConfig) GetBool(key string) bool {
2828
return isTruthy(self.Get(key))
2929
}
30+
31+
func (self *FakeGitConfig) DropCache() {
32+
}

pkg/gui/gui.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, contextKey types.Context
331331

332332
gui.g.SetFocusHandler(func(Focused bool) error {
333333
if Focused {
334+
gui.git.Config.DropConfigCache()
335+
334336
oldConfig := gui.Config.GetUserConfig()
335337
reloadErr, didChange := gui.Config.ReloadChangedUserConfigFiles()
336338
if didChange && reloadErr == nil {

0 commit comments

Comments
 (0)