Skip to content

Commit

Permalink
bit sync provides multiple options for handling diverged branch.
Browse files Browse the repository at this point in the history
- fixes #15
  • Loading branch information
chriswalz committed Oct 30, 2020
1 parent 2389581 commit b9f76f8
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"github.com/AlecAivazis/survey/v2"
"github.com/spf13/cobra"
"strings"
)
Expand All @@ -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()})
Expand Down

0 comments on commit b9f76f8

Please sign in to comment.