mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-08 22:36:49 +02:00
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.
This commit is contained in:
@@ -111,3 +111,7 @@ func (self *ConfigCommands) GetCoreCommentChar() byte {
|
||||
func (self *ConfigCommands) GetRebaseUpdateRefs() bool {
|
||||
return self.gitConfig.GetBool("rebase.updateRefs")
|
||||
}
|
||||
|
||||
func (self *ConfigCommands) DropConfigCache() {
|
||||
self.gitConfig.DropCache()
|
||||
}
|
||||
|
@@ -15,6 +15,8 @@ type IGitConfig interface {
|
||||
GetGeneral(string) string
|
||||
// this is for when you want to pass 'mykey' and check if the result is truthy
|
||||
GetBool(string) bool
|
||||
|
||||
DropCache()
|
||||
}
|
||||
|
||||
type CachedGitConfig struct {
|
||||
@@ -93,3 +95,10 @@ func isTruthy(value string) bool {
|
||||
lcValue := strings.ToLower(value)
|
||||
return lcValue == "true" || lcValue == "1" || lcValue == "yes" || lcValue == "on"
|
||||
}
|
||||
|
||||
func (self *CachedGitConfig) DropCache() {
|
||||
self.mutex.Lock()
|
||||
defer self.mutex.Unlock()
|
||||
|
||||
self.cache = make(map[string]string)
|
||||
}
|
||||
|
@@ -27,3 +27,6 @@ func (self *FakeGitConfig) GetGeneral(args string) string {
|
||||
func (self *FakeGitConfig) GetBool(key string) bool {
|
||||
return isTruthy(self.Get(key))
|
||||
}
|
||||
|
||||
func (self *FakeGitConfig) DropCache() {
|
||||
}
|
||||
|
@@ -115,7 +115,7 @@ func TestListRenderer_renderLines(t *testing.T) {
|
||||
}
|
||||
for _, s := range scenarios {
|
||||
t.Run(s.name, func(t *testing.T) {
|
||||
viewModel := NewListViewModel[mystring](func() []mystring { return s.modelStrings })
|
||||
viewModel := NewListViewModel(func() []mystring { return s.modelStrings })
|
||||
var getNonModelItems func() []*NonModelItem
|
||||
if s.nonModelIndices != nil {
|
||||
getNonModelItems = func() []*NonModelItem {
|
||||
@@ -236,7 +236,7 @@ func TestListRenderer_ModelIndexToViewIndex_and_back(t *testing.T) {
|
||||
assert.Equal(t, len(s.viewIndices), len(s.expectedModelIndices))
|
||||
|
||||
modelInts := lo.Map(lo.Range(s.numModelItems), func(i int, _ int) myint { return myint(i) })
|
||||
viewModel := NewListViewModel[myint](func() []myint { return modelInts })
|
||||
viewModel := NewListViewModel(func() []myint { return modelInts })
|
||||
var getNonModelItems func() []*NonModelItem
|
||||
if s.nonModelIndices != nil {
|
||||
getNonModelItems = func() []*NonModelItem {
|
||||
|
@@ -331,6 +331,8 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, contextKey types.Context
|
||||
|
||||
gui.g.SetFocusHandler(func(Focused bool) error {
|
||||
if Focused {
|
||||
gui.git.Config.DropConfigCache()
|
||||
|
||||
oldConfig := gui.Config.GetUserConfig()
|
||||
reloadErr, didChange := gui.Config.ReloadChangedUserConfigFiles()
|
||||
if didChange && reloadErr == nil {
|
||||
|
Reference in New Issue
Block a user