From 3822ca8e92f7421ac7bb76c9942599737894ab50 Mon Sep 17 00:00:00 2001 From: Fabian Siegel Date: Fri, 26 Nov 2021 01:05:44 +0100 Subject: [PATCH] sync: use `push --force-with-lease` when rebasing with push enabled (#20) --- cmd/commands/pr/sync/sync.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/commands/pr/sync/sync.go b/cmd/commands/pr/sync/sync.go index b7f2522..3d25886 100644 --- a/cmd/commands/pr/sync/sync.go +++ b/cmd/commands/pr/sync/sync.go @@ -97,8 +97,14 @@ func Add(prCmd *cobra.Command, globalOpts *options.GlobalOptions) { cmdQueue = append(cmdQueue, []string{"git", "fetch", remoteName, pr.Destination.Branch.Name}) if Method == MethodOptionRebase { cmdQueue = append(cmdQueue, []string{"git", "rebase", remoteDestinationBranch}) + if Push { + cmdQueue = append(cmdQueue, []string{"git", "push", "--force-with-lease"}) + } } else { cmdQueue = append(cmdQueue, []string{"git", "merge", "--commit", remoteDestinationBranch}) + if Push { + cmdQueue = append(cmdQueue, []string{"git", "push"}) + } } var builder strings.Builder @@ -124,18 +130,11 @@ func Add(prCmd *cobra.Command, globalOpts *options.GlobalOptions) { return } - if Push { - cmdQueue = [][]string{{"git", "push"}} - err = processCmdQueue(cmdQueue) - if err != nil { - logging.Error(err) - } - } }, } syncCmd.Flags().StringVar(&Method, "method", "merge", "sync using merge or rebase (merge/rebase)") - syncCmd.Flags().BoolVar(&Push, "push", true, "push after merge/rebase") + syncCmd.Flags().BoolVar(&Push, "push", true, "push after merge/push --force-with-lease after rebase") prCmd.AddCommand(syncCmd) } @@ -147,6 +146,7 @@ func processCmdQueue(cmdQueue [][]string) error { if err != nil { return err } + logging.Note(strings.Join(args, " ")) cmd := exec.Command(exe, args[1:]...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr