From b9f76f8b49d3c155dcbd32f5a51f4a4c9b9afdf6 Mon Sep 17 00:00:00 2001 From: chriswalz Date: Wed, 28 Oct 2020 23:07:22 -0400 Subject: [PATCH] bit sync provides multiple options for handling diverged branch. - fixes #15 --- cmd/sync.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/cmd/sync.go b/cmd/sync.go index 08836f2..54e2465 100644 --- a/cmd/sync.go +++ b/cmd/sync.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "github.com/AlecAivazis/survey/v2" "github.com/spf13/cobra" "strings" ) @@ -20,11 +21,33 @@ sync local-branch // if possibly squashed if IsDiverged() { RunInTerminalWithColor("git", []string{"status", "-sb", "--untracked-files=no"}) - yes := AskConfirm("Force (destructive) push to origin/" + CurrentBranch() + "?") - if yes { + + ans := "" + optionMap := map[string]string{ + "rebase": "Rebase on origin/upstream", + "force": "Force (destructive) push to origin/" + CurrentBranch(), + "cancel": "Cancel", + } + prompt := &survey.Select{ + Message: "Branch is diverged from origin/upstream – handle by...", + Options: []string{ + optionMap["rebase"], + optionMap["force"], + optionMap["cancel"], + }, + } + fmt.Println() + survey.AskOne(prompt, &ans) + if ans == optionMap["rebase"] { + RunInTerminalWithColor("git", []string{"pull", "-r"}) + return + } else if ans == optionMap["force"] { RunInTerminalWithColor("git", []string{"push", "--force-with-lease"}) + // dont return user may have additional changes to save + } else { + fmt.Println("Canceling...") + return } - return } if !CloudBranchExists() { RunInTerminalWithColor("git", []string{"push", "--set-upstream", "origin", CurrentBranch()})