summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2018-09-25 20:31:19 +1000
committerJesse Duffield <jessedduffield@gmail.com>2018-09-25 20:31:19 +1000
commiteb69d98f99f77669ffbb8463f6f6d84441c638d4 (patch)
tree5c53873b6d1fc1896948836c0a96755c36719259
parentfb9596a3fffa5c707b27fb0eee1768d76aefd206 (diff)
add test for CurrentBranchName
-rw-r--r--pkg/commands/git.go6
-rw-r--r--pkg/commands/git_test.go12
2 files changed, 17 insertions, 1 deletions
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)
+}