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 65ee0bc
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 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,9 +21,22 @@ 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 := ""
prompt := &survey.Select{
Message: "Branch is diverged from origin/upstream – handle by...",
Options: []string{
"Rebase on origin/upstream",
"Force (destructive) push to origin/" + CurrentBranch(),
"Cancel"},
}
survey.AskOne(prompt, &ans)
if strings.HasPrefix(ans, "Rebase") {
RunInTerminalWithColor("git", []string{"pull", "-r"})
} else if strings.HasPrefix(ans, "Force") {
RunInTerminalWithColor("git", []string{"push", "--force-with-lease"})
} else {
fmt.Println("Canceling..")
}
return
}
Expand Down

0 comments on commit 65ee0bc

Please sign in to comment.