mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-10-29 15:09:22 +03:00
Add config migration of paging section to pagers array
This commit is contained in:
@@ -310,6 +310,11 @@ func computeMigratedConfig(path string, content []byte, changes *ChangesSet) ([]
|
||||
return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %w", path, err)
|
||||
}
|
||||
|
||||
err = migratePagers(&rootNode, changes)
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("Couldn't migrate config file at `%s`: %w", path, err)
|
||||
}
|
||||
|
||||
// Add more migrations here...
|
||||
|
||||
if reflect.DeepEqual(rootNode, originalCopy) {
|
||||
@@ -469,6 +474,37 @@ func migrateAllBranchesLogCmd(rootNode *yaml.Node, changes *ChangesSet) error {
|
||||
})
|
||||
}
|
||||
|
||||
func migratePagers(rootNode *yaml.Node, changes *ChangesSet) error {
|
||||
return yaml_utils.TransformNode(rootNode, []string{"git"}, func(gitNode *yaml.Node) error {
|
||||
pagingKeyNode, pagingValueNode := yaml_utils.LookupKey(gitNode, "paging")
|
||||
if pagingKeyNode == nil || pagingValueNode.Kind != yaml.MappingNode {
|
||||
// If there's no "paging" section (or it's not an object), there's nothing to do
|
||||
return nil
|
||||
}
|
||||
|
||||
pagersKeyNode, _ := yaml_utils.LookupKey(gitNode, "pagers")
|
||||
if pagersKeyNode != nil {
|
||||
// Conversely, if there *is* already a "pagers" array, we also have nothing to do.
|
||||
// This covers the case where the user keeps both the "paging" section and the "pagers"
|
||||
// array for the sake of easier testing of old versions.
|
||||
return nil
|
||||
}
|
||||
|
||||
pagingKeyNode.Value = "pagers"
|
||||
pagingContentCopy := pagingValueNode.Content
|
||||
pagingValueNode.Kind = yaml.SequenceNode
|
||||
pagingValueNode.Tag = "!!seq"
|
||||
pagingValueNode.Content = []*yaml.Node{{
|
||||
Kind: yaml.MappingNode,
|
||||
Content: pagingContentCopy,
|
||||
}}
|
||||
|
||||
changes.Add("Moved git.paging object to git.pagers array")
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (c *AppConfig) GetDebug() bool {
|
||||
return c.debug
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user