From 9713a151672d0787c24b922ab70e0177ac4607de Mon Sep 17 00:00:00 2001 From: Anthony HAMON Date: Sun, 16 Sep 2018 22:12:03 +0200 Subject: [PATCH] commands/git : add test to GetBranchGraph, refactor --- pkg/commands/git.go | 2 +- pkg/commands/git_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 402bee7ac..1c5b31b81 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -451,7 +451,7 @@ func (c *GitCommand) PrepareCommitAmendSubProcess() *exec.Cmd { // Currently it limits the result to 100 commits, but when we get async stuff // working we can do lazy loading func (c *GitCommand) GetBranchGraph(branchName string) (string, error) { - return c.OSCommand.RunCommandWithOutput("git log --graph --color --abbrev-commit --decorate --date=relative --pretty=medium -100 " + branchName) + return c.OSCommand.RunCommandWithOutput(fmt.Sprintf("git log --graph --color --abbrev-commit --decorate --date=relative --pretty=medium -100 %s", branchName)) } func includesString(list []string, a string) bool { diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index 87b0e4cee..7a7af0991 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -1467,6 +1467,19 @@ func TestGitCommandCheckout(t *testing.T) { } } +func TestGitCommandGetBranchGraph(t *testing.T) { + gitCmd := newDummyGitCommand() + gitCmd.OSCommand.command = func(cmd string, args ...string) *exec.Cmd { + assert.EqualValues(t, "git", cmd) + assert.EqualValues(t, []string{"log", "--graph", "--color", "--abbrev-commit", "--decorate", "--date=relative", "--pretty=medium", "-100", "test"}, args) + + return exec.Command("echo") + } + + _, err := gitCmd.GetBranchGraph("test") + assert.NoError(t, err) +} + func TestGitCommandDiff(t *testing.T) { gitCommand := newDummyGitCommand() assert.NoError(t, test.GenerateRepo("lots_of_diffs.sh"))