mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-17 00:18:05 +02:00
add test for CurrentBranchName
This commit is contained in:
@ -268,7 +268,11 @@ func (c *GitCommand) NewBranch(name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *GitCommand) CurrentBranchName() (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
|
// DeleteBranch delete branch
|
||||||
|
@ -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)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user