Migrate null keybindings to "<disabled>"

Unfortunately the migration code requires yaml v3, but our yaml fork is based on
v2, so we need to import both in app_config.go in this commit, which is ugly. We
can clean this up in the next commit.
This commit is contained in:
Stefan Haller
2024-03-29 17:14:43 +01:00
parent 4d8b8b647a
commit 93aee0dca0

View File

@@ -9,6 +9,7 @@ import (
"github.com/adrg/xdg"
"github.com/jesseduffield/lazygit/pkg/utils/yaml_utils"
yaml "github.com/jesseduffield/yaml"
yaml3 "gopkg.in/yaml.v3"
)
// AppConfig contains the base configuration fields required for lazygit.
@@ -180,6 +181,11 @@ func migrateUserConfig(path string, content []byte) ([]byte, error) {
return nil, fmt.Errorf("Couldn't migrate config file at `%s`: %s", path, err)
}
changedContent, err = changeNullKeybindingsToDisabled(changedContent)
if err != nil {
return nil, fmt.Errorf("Couldn't migrate config file at `%s`: %s", path, err)
}
// Add more migrations here...
// Write config back if changed
@@ -193,6 +199,17 @@ func migrateUserConfig(path string, content []byte) ([]byte, error) {
return content, nil
}
func changeNullKeybindingsToDisabled(changedContent []byte) ([]byte, error) {
return yaml_utils.Walk(changedContent, func(node *yaml3.Node, path string) bool {
if strings.HasPrefix(path, "keybinding.") && node.Kind == yaml3.ScalarNode && node.Tag == "!!null" {
node.Value = "<disabled>"
node.Tag = "!!str"
return true
}
return false
})
}
func (c *AppConfig) GetDebug() bool {
return c.Debug
}