From 93aee0dca0eda9ce51312e4d42040f69dcdfeaac Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 29 Mar 2024 17:14:43 +0100 Subject: [PATCH] Migrate null keybindings to "" 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. --- pkg/config/app_config.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 7f5757447..aa891d1f1 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -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 = "" + node.Tag = "!!str" + return true + } + return false + }) +} + func (c *AppConfig) GetDebug() bool { return c.Debug }