mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-13 13:59:06 +02:00
Merge pull request #188 from jesseduffield/feature/force-push
Force push confirmation panel
This commit is contained in:
commit
8364509d1f
@ -270,8 +270,12 @@ func (c *GitCommand) Pull() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Push push to a branch
|
// Push push to a branch
|
||||||
func (c *GitCommand) Push(branchName string) error {
|
func (c *GitCommand) Push(branchName string, force bool) error {
|
||||||
return c.OSCommand.RunCommand("git push -u origin " + branchName)
|
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
|
// SquashPreviousTwoCommits squashes a commit down to the one below it
|
||||||
|
@ -360,21 +360,35 @@ func (gui *Gui) pullFiles(g *gocui.Gui, v *gocui.View) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) pushFiles(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) pushWithForceFlag(currentView *gocui.View, force bool) error {
|
||||||
gui.createMessagePanel(g, v, "", gui.Tr.SLocalize("PushWait"))
|
if err := gui.createMessagePanel(gui.g, currentView, "", gui.Tr.SLocalize("PushWait")); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
go func() {
|
go func() {
|
||||||
branchName := gui.State.Branches[0].Name
|
branchName := gui.State.Branches[0].Name
|
||||||
if err := gui.GitCommand.Push(branchName); err != nil {
|
if err := gui.GitCommand.Push(branchName, force); err != nil {
|
||||||
gui.createErrorPanel(g, err.Error())
|
_ = gui.createErrorPanel(gui.g, err.Error())
|
||||||
} else {
|
} else {
|
||||||
gui.closeConfirmationPrompt(g)
|
_ = gui.closeConfirmationPrompt(gui.g)
|
||||||
gui.refreshCommits(g)
|
_ = gui.refreshCommits(gui.g)
|
||||||
gui.refreshStatus(g)
|
_ = gui.refreshStatus(gui.g)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
return nil
|
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 {
|
func (gui *Gui) handleSwitchToMerge(g *gocui.Gui, v *gocui.View) error {
|
||||||
mergeView, err := g.View("main")
|
mergeView, err := g.View("main")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -300,6 +300,12 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "EditConfig",
|
ID: "EditConfig",
|
||||||
Other: "edit config file",
|
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.",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user