diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-01-07 20:12:36 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-01-07 20:26:01 +1100 |
commit | eb2bfd3848bc5178670380f77b675a27d94d2515 (patch) | |
tree | 7cc71d45667144061a9ced2cc1b9e04afa1a0d45 /pkg/commands | |
parent | adb5c8fe06107c01003c444c4636f19713ea9404 (diff) |
allow hard resetting to upstream branch
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/git.go | 14 | ||||
-rw-r--r-- | pkg/commands/git_test.go | 8 |
2 files changed, 12 insertions, 10 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 08eb78edf..ab71f80e3 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -265,7 +265,7 @@ func includesInt(list []int, a int) bool { // ResetAndClean removes all unstaged changes and removes all untracked files func (c *GitCommand) ResetAndClean() error { - if err := c.ResetHardHead(); err != nil { + if err := c.ResetHard("HEAD"); err != nil { return err } @@ -961,14 +961,14 @@ func (c *GitCommand) RemoveUntrackedFiles() error { return c.OSCommand.RunCommand("git clean -fd") } -// ResetHardHead runs `git reset --hard HEAD` -func (c *GitCommand) ResetHardHead() error { - return c.OSCommand.RunCommand("git reset --hard HEAD") +// ResetHardHead runs `git reset --hard` +func (c *GitCommand) ResetHard(ref string) error { + return c.OSCommand.RunCommand("git reset --hard " + ref) } -// ResetSoftHead runs `git reset --soft HEAD` -func (c *GitCommand) ResetSoftHead() error { - return c.OSCommand.RunCommand("git reset --soft HEAD") +// ResetSoft runs `git reset --soft HEAD` +func (c *GitCommand) ResetSoft(ref string) error { + return c.OSCommand.RunCommand("git reset --soft " + ref) } // DiffCommits show diff between commits diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index 4991714f1..0429165de 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -2106,10 +2106,11 @@ func TestGitCommandRemoveUntrackedFiles(t *testing.T) { } } -// TestGitCommandResetHardHead is a function. -func TestGitCommandResetHardHead(t *testing.T) { +// TestGitCommandResetHard is a function. +func TestGitCommandResetHard(t *testing.T) { type scenario struct { testName string + ref string command func(string, ...string) *exec.Cmd test func(error) } @@ -2117,6 +2118,7 @@ func TestGitCommandResetHardHead(t *testing.T) { scenarios := []scenario{ { "valid case", + "HEAD", test.CreateMockCommand(t, []*test.CommandSwapper{ { Expect: `git reset --hard HEAD`, @@ -2134,7 +2136,7 @@ func TestGitCommandResetHardHead(t *testing.T) { for _, s := range scenarios { t.Run(s.testName, func(t *testing.T) { gitCmd.OSCommand.command = s.command - s.test(gitCmd.ResetHardHead()) + s.test(gitCmd.ResetHard(s.ref)) }) } } |