11package config
22
33import (
4+ "errors"
45 "fmt"
56 "log"
67 "os"
@@ -10,6 +11,7 @@ import (
1011 "time"
1112
1213 "github.com/adrg/xdg"
14+ "github.com/jesseduffield/lazygit/pkg/utils"
1315 "github.com/jesseduffield/lazygit/pkg/utils/yaml_utils"
1416 "github.com/samber/lo"
1517 "gopkg.in/yaml.v3"
@@ -286,6 +288,11 @@ func computeMigratedConfig(path string, content []byte) ([]byte, error) {
286288 return nil , fmt .Errorf ("Couldn't migrate config file at `%s`: %s" , path , err )
287289 }
288290
291+ err = migrateAllBranchesLogCmd (& rootNode )
292+ if err != nil {
293+ return nil , fmt .Errorf ("Couldn't migrate config file at `%s`: %s" , path , err )
294+ }
295+
289296 // Add more migrations here...
290297
291298 if ! reflect .DeepEqual (rootNode , originalCopy ) {
@@ -386,6 +393,44 @@ func changeCustomCommandStreamAndOutputToOutputEnum(rootNode *yaml.Node) error {
386393 })
387394}
388395
396+ // This migration is special because users have already defined
397+ // a single element at `allBranchesLogCmd` and the sequence at `allBranchesLogCmds`.
398+ // Some users have explicitly set `allBranchesLogCmd` to be an empty string in order
399+ // to remove it, so in that case we just delete the element, and add nothing to the list
400+ func migrateAllBranchesLogCmd (rootNode * yaml.Node ) error {
401+ return yaml_utils .TransformNode (rootNode , []string {"git" }, func (gitNode * yaml.Node ) error {
402+ cmdKeyNode , cmdValueNode := yaml_utils .LookupKey (gitNode , "allBranchesLogCmd" )
403+ // Nothing to do if they do not have the deprecated item
404+ if cmdKeyNode == nil {
405+ return nil
406+ }
407+
408+ cmdsKeyNode , cmdsValueNode := yaml_utils .LookupKey (gitNode , "allBranchesLogCmds" )
409+ if cmdsKeyNode == nil {
410+ // Create empty sequence node and attach it onto the root git node
411+ // We will later populate it with the individual allBranchesLogCmd record
412+ cmdsKeyNode = & yaml.Node {Kind : yaml .ScalarNode , Value : "allBranchesLogCmds" }
413+ cmdsValueNode = & yaml.Node {Kind : yaml .SequenceNode , Content : []* yaml.Node {}}
414+ gitNode .Content = append (gitNode .Content ,
415+ cmdsKeyNode ,
416+ cmdsValueNode ,
417+ )
418+ } else if cmdsValueNode .Kind != yaml .SequenceNode {
419+ return errors .New ("You should have an allBranchesLogCmds defined as a sequence!" )
420+ }
421+
422+ if cmdValueNode .Value != "" {
423+ // Prepending the individual element to make it show up first in the list, which was prior behavior
424+ cmdsValueNode .Content = utils .Prepend (cmdsValueNode .Content , & yaml.Node {Kind : yaml .ScalarNode , Value : cmdValueNode .Value })
425+ }
426+
427+ // Clear out the existing allBranchesLogCmd, now that we have migrated it into the list
428+ _ , _ = yaml_utils .RemoveKey (gitNode , "allBranchesLogCmd" )
429+
430+ return nil
431+ })
432+ }
433+
389434func (c * AppConfig ) GetDebug () bool {
390435 return c .debug
391436}
0 commit comments