1
1
package config
2
2
3
3
import (
4
+ "errors"
4
5
"fmt"
5
6
"log"
6
7
"os"
@@ -10,6 +11,7 @@ import (
10
11
"time"
11
12
12
13
"github.com/adrg/xdg"
14
+ "github.com/jesseduffield/lazygit/pkg/utils"
13
15
"github.com/jesseduffield/lazygit/pkg/utils/yaml_utils"
14
16
"github.com/samber/lo"
15
17
"gopkg.in/yaml.v3"
@@ -286,6 +288,11 @@ func computeMigratedConfig(path string, content []byte) ([]byte, error) {
286
288
return nil , fmt .Errorf ("Couldn't migrate config file at `%s`: %s" , path , err )
287
289
}
288
290
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
+
289
296
// Add more migrations here...
290
297
291
298
if ! reflect .DeepEqual (rootNode , originalCopy ) {
@@ -386,6 +393,44 @@ func changeCustomCommandStreamAndOutputToOutputEnum(rootNode *yaml.Node) error {
386
393
})
387
394
}
388
395
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
+
389
434
func (c * AppConfig ) GetDebug () bool {
390
435
return c .debug
391
436
}
0 commit comments