Skip to content

Commit

Permalink
sync: show note if merge or rebase failed; only push if previous oper…
Browse files Browse the repository at this point in the history
…ation successful
  • Loading branch information
craftamap committed Aug 8, 2021
1 parent 685a336 commit adfb6c2
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions cmd/commands/pr/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -20,14 +21,14 @@ var (

func Add(prCmd *cobra.Command, globalOpts *options.GlobalOptions) {
syncCmd := &cobra.Command{
Use: "sync [<number of pr>]",
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

Expand Down Expand Up @@ -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)
}
}
},
}

Expand Down

0 comments on commit adfb6c2

Please # to comment.