Skip to content

Commit 357c046

Browse files
authored
Drop the git config cache when getting focus (#4376)
- **PR Description** 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. Addresses #4240.
2 parents f5f2464 + 3e15be5 commit 357c046

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
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/context/list_renderer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func TestListRenderer_renderLines(t *testing.T) {
115115
}
116116
for _, s := range scenarios {
117117
t.Run(s.name, func(t *testing.T) {
118-
viewModel := NewListViewModel[mystring](func() []mystring { return s.modelStrings })
118+
viewModel := NewListViewModel(func() []mystring { return s.modelStrings })
119119
var getNonModelItems func() []*NonModelItem
120120
if s.nonModelIndices != nil {
121121
getNonModelItems = func() []*NonModelItem {
@@ -236,7 +236,7 @@ func TestListRenderer_ModelIndexToViewIndex_and_back(t *testing.T) {
236236
assert.Equal(t, len(s.viewIndices), len(s.expectedModelIndices))
237237

238238
modelInts := lo.Map(lo.Range(s.numModelItems), func(i int, _ int) myint { return myint(i) })
239-
viewModel := NewListViewModel[myint](func() []myint { return modelInts })
239+
viewModel := NewListViewModel(func() []myint { return modelInts })
240240
var getNonModelItems func() []*NonModelItem
241241
if s.nonModelIndices != nil {
242242
getNonModelItems = func() []*NonModelItem {

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)