From eb69d98f99f77669ffbb8463f6f6d84441c638d4 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 25 Sep 2018 20:31:19 +1000 Subject: add test for CurrentBranchName --- pkg/commands/git.go | 6 +++++- pkg/commands/git_test.go | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 4d132237f..402ec3378 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -268,7 +268,11 @@ func (c *GitCommand) NewBranch(name string) error { } func (c *GitCommand) CurrentBranchName() (string, error) { - return c.OSCommand.RunCommandWithOutput("git symbolic-ref --short HEAD") + output, err := c.OSCommand.RunCommandWithOutput("git symbolic-ref --short HEAD") + if err != nil { + return "", err + } + return utils.TrimTrailingNewline(output), nil } // DeleteBranch delete branch diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index d5b87a1f1..a2b2b9524 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -1763,3 +1763,15 @@ func TestGitCommandGetMergeBase(t *testing.T) { }) } } + +func TestGitCommandCurrentBranchName(t *testing.T) { + gitCmd := newDummyGitCommand() + gitCmd.OSCommand.command = func(cmd string, args ...string) *exec.Cmd { + assert.Equal(t, "git", cmd) + assert.EqualValues(t, []string{"symbolic-ref", "--short", "HEAD"}, args) + return exec.Command("echo", "master") + } + output, err := gitCmd.CurrentBranchName() + assert.Equal(t, "master", output) + assert.NoError(t, err) +} -- cgit v1.2.3