summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2018-08-20 19:52:41 +1000
committerGitHub <noreply@github.com>2018-08-20 19:52:41 +1000
commit8364509d1f91d470bfd5ddb388c8c4587ad88b44 (patch)
treefbd5fb85fe1b200d048b3dd4aee259ecbda02c30
parent64cf8f5b107a310e6729b68ba8d7638effd3966d (diff)
parent317926c808fe33f8818061abb4102941d9da6b67 (diff)
Merge pull request #188 from jesseduffield/feature/force-push
Force push confirmation panel
-rw-r--r--pkg/commands/git.go8
-rw-r--r--pkg/gui/files_panel.go28
-rw-r--r--pkg/i18n/english.go6
3 files changed, 33 insertions, 9 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index 557e6a8c0..bf9aa6646 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -270,8 +270,12 @@ func (c *GitCommand) Pull() error {
}
// Push push to a branch
-func (c *GitCommand) Push(branchName string) error {
- return c.OSCommand.RunCommand("git push -u origin " + branchName)
+func (c *GitCommand) Push(branchName string, force bool) error {
+ forceFlag := ""
+ if force {
+ forceFlag = "--force-with-lease "
+ }
+ return c.OSCommand.RunCommand("git push " + forceFlag + "-u origin " + branchName)
}
// SquashPreviousTwoCommits squashes a commit down to the one below it
diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go
index d614cf5ef..5791a9d15 100644
--- a/pkg/gui/files_panel.go
+++ b/pkg/gui/files_panel.go
@@ -360,21 +360,35 @@ func (gui *Gui) pullFiles(g *gocui.Gui, v *gocui.View) error {
return nil
}
-func (gui *Gui) pushFiles(g *gocui.Gui, v *gocui.View) error {
- gui.createMessagePanel(g, v, "", gui.Tr.SLocalize("PushWait"))
+func (gui *Gui) pushWithForceFlag(currentView *gocui.View, force bool) error {
+ if err := gui.createMessagePanel(gui.g, currentView, "", gui.Tr.SLocalize("PushWait")); err != nil {
+ return err
+ }
go func() {
branchName := gui.State.Branches[0].Name
- if err := gui.GitCommand.Push(branchName); err != nil {
- gui.createErrorPanel(g, err.Error())
+ if err := gui.GitCommand.Push(branchName, force); err != nil {
+ _ = gui.createErrorPanel(gui.g, err.Error())
} else {
- gui.closeConfirmationPrompt(g)
- gui.refreshCommits(g)
- gui.refreshStatus(g)
+ _ = gui.closeConfirmationPrompt(gui.g)
+ _ = gui.refreshCommits(gui.g)
+ _ = gui.refreshStatus(gui.g)
}
}()
return nil
}
+func (gui *Gui) pushFiles(g *gocui.Gui, v *gocui.View) error {
+ // if we have pullables we'll ask if the user wants to force push
+ _, pullables := gui.GitCommand.UpstreamDifferenceCount()
+ if pullables == "?" || pullables == "0" {
+ return gui.pushWithForceFlag(v, false)
+ }
+ err := gui.createConfirmationPanel(g, nil, gui.Tr.SLocalize("ForcePush"), gui.Tr.SLocalize("ForcePushPrompt"), func(g *gocui.Gui, v *gocui.View) error {
+ return gui.pushWithForceFlag(v, true)
+ }, nil)
+ return err
+}
+
func (gui *Gui) handleSwitchToMerge(g *gocui.Gui, v *gocui.View) error {
mergeView, err := g.View("main")
if err != nil {
diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go
index bebe9b282..c0384136b 100644
--- a/pkg/i18n/english.go
+++ b/pkg/i18n/english.go
@@ -300,6 +300,12 @@ func addEnglish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "EditConfig",
Other: "edit config file",
+ }, &i18n.Message{
+ ID: "ForcePush",
+ Other: "Force push",
+ }, &i18n.Message{
+ ID: "ForcePushPrompt",
+ Other: "Your branch has diverged from the remote branch. Press 'esc' to cancel, or 'enter' to force push.",
},
)
}