mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 04:45:47 +02:00
Show a confirmation when changing a config that can't be auto-reloaded
This commit is contained in:
parent
ce50533689
commit
57de11b709
2 changed files with 64 additions and 0 deletions
|
@ -6,6 +6,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -331,6 +332,7 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, contextKey types.Context
|
||||||
|
|
||||||
gui.g.SetFocusHandler(func(Focused bool) error {
|
gui.g.SetFocusHandler(func(Focused bool) error {
|
||||||
if Focused {
|
if Focused {
|
||||||
|
oldConfig := gui.Config.GetUserConfig()
|
||||||
reloadErr, didChange := gui.Config.ReloadChangedUserConfigFiles()
|
reloadErr, didChange := gui.Config.ReloadChangedUserConfigFiles()
|
||||||
if didChange && reloadErr == nil {
|
if didChange && reloadErr == nil {
|
||||||
gui.c.Log.Info("User config changed - reloading")
|
gui.c.Log.Info("User config changed - reloading")
|
||||||
|
@ -338,6 +340,10 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, contextKey types.Context
|
||||||
if err := gui.resetKeybindings(); err != nil {
|
if err := gui.resetKeybindings(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := gui.checkForChangedConfigsThatDontAutoReload(oldConfig, gui.Config.GetUserConfig()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.c.Log.Info("Receiving focus - refreshing")
|
gui.c.Log.Info("Receiving focus - refreshing")
|
||||||
|
@ -434,6 +440,56 @@ func (gui *Gui) onUserConfigLoaded() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) checkForChangedConfigsThatDontAutoReload(oldConfig *config.UserConfig, newConfig *config.UserConfig) error {
|
||||||
|
configsThatDontAutoReload := []string{
|
||||||
|
"Git.AutoFetch",
|
||||||
|
"Git.AutoRefresh",
|
||||||
|
"Refresher.RefreshInterval",
|
||||||
|
"Refresher.FetchInterval",
|
||||||
|
"Update.Method",
|
||||||
|
"Update.Days",
|
||||||
|
}
|
||||||
|
|
||||||
|
changedConfigs := []string{}
|
||||||
|
for _, config := range configsThatDontAutoReload {
|
||||||
|
old := reflect.ValueOf(oldConfig).Elem()
|
||||||
|
new := reflect.ValueOf(newConfig).Elem()
|
||||||
|
fieldNames := strings.Split(config, ".")
|
||||||
|
userFacingPath := make([]string, 0, len(fieldNames))
|
||||||
|
// navigate to the leaves in old and new config
|
||||||
|
for _, fieldName := range fieldNames {
|
||||||
|
f, _ := old.Type().FieldByName(fieldName)
|
||||||
|
userFacingName := f.Tag.Get("yaml")
|
||||||
|
if userFacingName == "" {
|
||||||
|
userFacingName = fieldName
|
||||||
|
}
|
||||||
|
userFacingPath = append(userFacingPath, userFacingName)
|
||||||
|
old = old.FieldByName(fieldName)
|
||||||
|
new = new.FieldByName(fieldName)
|
||||||
|
}
|
||||||
|
// if the value has changed, ...
|
||||||
|
if !old.Equal(new) {
|
||||||
|
// ... append it to the list of changed configs
|
||||||
|
changedConfigs = append(changedConfigs, strings.Join(userFacingPath, "."))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(changedConfigs) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
message := utils.ResolvePlaceholderString(
|
||||||
|
gui.c.Tr.NonReloadableConfigWarning,
|
||||||
|
map[string]string{
|
||||||
|
"configs": strings.Join(changedConfigs, "\n"),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return gui.c.Confirm(types.ConfirmOpts{
|
||||||
|
Title: gui.c.Tr.NonReloadableConfigWarningTitle,
|
||||||
|
Prompt: message,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// resetState reuses the repo state from our repo state map, if the repo was
|
// resetState reuses the repo state from our repo state map, if the repo was
|
||||||
// open before; otherwise it creates a new one.
|
// open before; otherwise it creates a new one.
|
||||||
func (gui *Gui) resetState(startArgs appTypes.StartArgs) types.Context {
|
func (gui *Gui) resetState(startArgs appTypes.StartArgs) types.Context {
|
||||||
|
|
|
@ -225,6 +225,8 @@ type TranslationSet struct {
|
||||||
MergeToolPrompt string
|
MergeToolPrompt string
|
||||||
IntroPopupMessage string
|
IntroPopupMessage string
|
||||||
DeprecatedEditConfigWarning string
|
DeprecatedEditConfigWarning string
|
||||||
|
NonReloadableConfigWarningTitle string
|
||||||
|
NonReloadableConfigWarning string
|
||||||
GitconfigParseErr string
|
GitconfigParseErr string
|
||||||
EditFile string
|
EditFile string
|
||||||
EditFileTooltip string
|
EditFileTooltip string
|
||||||
|
@ -985,6 +987,10 @@ for up-to-date information how to configure your editor.
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const englishNonReloadableConfigWarning = `The following config settings were changed, but the change doesn't take effect immediately. Please quit and restart lazygit for changes to take effect:
|
||||||
|
|
||||||
|
{{configs}}`
|
||||||
|
|
||||||
// exporting this so we can use it in tests
|
// exporting this so we can use it in tests
|
||||||
func EnglishTranslationSet() *TranslationSet {
|
func EnglishTranslationSet() *TranslationSet {
|
||||||
return &TranslationSet{
|
return &TranslationSet{
|
||||||
|
@ -1199,6 +1205,8 @@ func EnglishTranslationSet() *TranslationSet {
|
||||||
MergeToolPrompt: "Are you sure you want to open `git mergetool`?",
|
MergeToolPrompt: "Are you sure you want to open `git mergetool`?",
|
||||||
IntroPopupMessage: englishIntroPopupMessage,
|
IntroPopupMessage: englishIntroPopupMessage,
|
||||||
DeprecatedEditConfigWarning: englishDeprecatedEditConfigWarning,
|
DeprecatedEditConfigWarning: englishDeprecatedEditConfigWarning,
|
||||||
|
NonReloadableConfigWarningTitle: "Config changed",
|
||||||
|
NonReloadableConfigWarning: englishNonReloadableConfigWarning,
|
||||||
GitconfigParseErr: `Gogit failed to parse your gitconfig file due to the presence of unquoted '\' characters. Removing these should fix the issue.`,
|
GitconfigParseErr: `Gogit failed to parse your gitconfig file due to the presence of unquoted '\' characters. Removing these should fix the issue.`,
|
||||||
EditFile: `Edit file`,
|
EditFile: `Edit file`,
|
||||||
EditFileTooltip: "Open file in external editor.",
|
EditFileTooltip: "Open file in external editor.",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue