1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-28 16:02:01 +03:00

allow hard resetting to upstream branch

This commit is contained in:
Jesse Duffield
2020-01-07 20:12:36 +11:00
parent adb5c8fe06
commit eb2bfd3848
4 changed files with 25 additions and 13 deletions

View File

@ -265,7 +265,7 @@ func includesInt(list []int, a int) bool {
// ResetAndClean removes all unstaged changes and removes all untracked files // ResetAndClean removes all unstaged changes and removes all untracked files
func (c *GitCommand) ResetAndClean() error { func (c *GitCommand) ResetAndClean() error {
if err := c.ResetHardHead(); err != nil { if err := c.ResetHard("HEAD"); err != nil {
return err return err
} }
@ -961,14 +961,14 @@ func (c *GitCommand) RemoveUntrackedFiles() error {
return c.OSCommand.RunCommand("git clean -fd") return c.OSCommand.RunCommand("git clean -fd")
} }
// ResetHardHead runs `git reset --hard HEAD` // ResetHardHead runs `git reset --hard`
func (c *GitCommand) ResetHardHead() error { func (c *GitCommand) ResetHard(ref string) error {
return c.OSCommand.RunCommand("git reset --hard HEAD") return c.OSCommand.RunCommand("git reset --hard " + ref)
} }
// ResetSoftHead runs `git reset --soft HEAD` // ResetSoft runs `git reset --soft HEAD`
func (c *GitCommand) ResetSoftHead() error { func (c *GitCommand) ResetSoft(ref string) error {
return c.OSCommand.RunCommand("git reset --soft HEAD") return c.OSCommand.RunCommand("git reset --soft " + ref)
} }
// DiffCommits show diff between commits // DiffCommits show diff between commits

View File

@ -2106,10 +2106,11 @@ func TestGitCommandRemoveUntrackedFiles(t *testing.T) {
} }
} }
// TestGitCommandResetHardHead is a function. // TestGitCommandResetHard is a function.
func TestGitCommandResetHardHead(t *testing.T) { func TestGitCommandResetHard(t *testing.T) {
type scenario struct { type scenario struct {
testName string testName string
ref string
command func(string, ...string) *exec.Cmd command func(string, ...string) *exec.Cmd
test func(error) test func(error)
} }
@ -2117,6 +2118,7 @@ func TestGitCommandResetHardHead(t *testing.T) {
scenarios := []scenario{ scenarios := []scenario{
{ {
"valid case", "valid case",
"HEAD",
test.CreateMockCommand(t, []*test.CommandSwapper{ test.CreateMockCommand(t, []*test.CommandSwapper{
{ {
Expect: `git reset --hard HEAD`, Expect: `git reset --hard HEAD`,
@ -2134,7 +2136,7 @@ func TestGitCommandResetHardHead(t *testing.T) {
for _, s := range scenarios { for _, s := range scenarios {
t.Run(s.testName, func(t *testing.T) { t.Run(s.testName, func(t *testing.T) {
gitCmd.OSCommand.command = s.command gitCmd.OSCommand.command = s.command
s.test(gitCmd.ResetHardHead()) s.test(gitCmd.ResetHard(s.ref))
}) })
} }
} }

View File

@ -604,14 +604,21 @@ func (gui *Gui) handleCreateResetMenu(g *gocui.Gui, v *gocui.View) error {
description: gui.Tr.SLocalize("softReset"), description: gui.Tr.SLocalize("softReset"),
command: "git reset --soft HEAD", command: "git reset --soft HEAD",
handler: func() error { handler: func() error {
return gui.GitCommand.ResetSoftHead() return gui.GitCommand.ResetSoft("HEAD")
}, },
}, },
{ {
description: gui.Tr.SLocalize("hardReset"), description: gui.Tr.SLocalize("hardReset"),
command: "git reset --hard HEAD", command: "git reset --hard HEAD",
handler: func() error { handler: func() error {
return gui.GitCommand.ResetHardHead() return gui.GitCommand.ResetHard("HEAD")
},
},
{
description: gui.Tr.SLocalize("hardResetUpstream"),
command: "git reset --hard @{upstream}",
handler: func() error {
return gui.GitCommand.ResetHard("@{upstream}")
}, },
}, },
{ {
@ -624,7 +631,7 @@ func (gui *Gui) handleCreateResetMenu(g *gocui.Gui, v *gocui.View) error {
handleMenuPress := func(index int) error { handleMenuPress := func(index int) error {
if err := options[index].handler(); err != nil { if err := options[index].handler(); err != nil {
return err return gui.createErrorPanel(gui.g, err.Error())
} }
return gui.refreshFiles() return gui.refreshFiles()

View File

@ -753,6 +753,9 @@ func addEnglish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{ }, &i18n.Message{
ID: "hardReset", ID: "hardReset",
Other: "hard reset", Other: "hard reset",
}, &i18n.Message{
ID: "hardResetUpstream",
Other: "hard reset to upstream branch",
}, &i18n.Message{ }, &i18n.Message{
ID: "viewResetOptions", ID: "viewResetOptions",
Other: `view reset options`, Other: `view reset options`,