From adfb6c27cec483f539c6e9b3c9229da2b4a4a910 Mon Sep 17 00:00:00 2001 From: Fabian Siegel Date: Sat, 7 Aug 2021 17:21:10 +0200 Subject: [PATCH] sync: show note if merge or rebase failed; only push if previous operation successful --- cmd/commands/pr/sync/sync.go | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/cmd/commands/pr/sync/sync.go b/cmd/commands/pr/sync/sync.go index eb80a0e..40012ad 100644 --- a/cmd/commands/pr/sync/sync.go +++ b/cmd/commands/pr/sync/sync.go @@ -10,6 +10,7 @@ import ( "github.com/craftamap/bb/cmd/options" "github.com/craftamap/bb/internal/run" "github.com/craftamap/bb/util/logging" + "github.com/logrusorgru/aurora" "github.com/spf13/cobra" ) @@ -20,14 +21,14 @@ var ( func Add(prCmd *cobra.Command, globalOpts *options.GlobalOptions) { syncCmd := &cobra.Command{ - Use: "sync []", - Long: "Sync a pull request on Bitbucket.org", - Short: "Sync a pull request", + Use: "sync", + Long: "synchronizes the current pull request with new changes in it's destination branch by either merging or rebasing the changes locally. If the rebase or merge fails because of an conflict, the merge must be resolved manually.", + Short: "Sync a pull request locally", Annotations: map[string]string{ "RequiresClient": "true", "RequiresRepository": "true", }, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { var id int var err error @@ -66,12 +67,26 @@ func Add(prCmd *cobra.Command, globalOpts *options.GlobalOptions) { } else { cmdQueue = append(cmdQueue, []string{"git", "merge", "--commit", remoteDestinationBranch}) } - if Push { - cmdQueue = append(cmdQueue, []string{"git", "push"}) - } - processCmdQueue(cmdQueue) + err = processCmdQueue(cmdQueue) + if err != nil { + logging.Error(err) + logging.Note("Looks like an error occured - you probably need to resolve the conflict manually now. Start by running " + aurora.BgBrightBlack(aurora.White(" git status ")).String() + " to get hints on how to resolve the conflicts.") + cancelCommand := aurora.BgBrightBlack(aurora.White(" git merge --abort ")).String() + if Rebase { + cancelCommand = aurora.BgBrightBlack(aurora.White(" git rebase --abort ")).String() + } + logging.Note("If you don't know how to resolve a conflict manually, you can run " + cancelCommand + " to reset.") + return + } + if Push { + cmdQueue = [][]string{{"git", "push"}} + err = processCmdQueue(cmdQueue) + if err != nil { + logging.Error(err) + } + } }, }