From 1cc7e9c02a9bd8426c2712eb5551965e2ddd5f13 Mon Sep 17 00:00:00 2001 From: Anthony HAMON Date: Wed, 5 Sep 2018 22:16:26 +0200 Subject: [PATCH 1/9] rewrite to use subtests --- pkg/commands/git_test.go | 104 +++++++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 37 deletions(-) diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index 777eebaec..db05e2e07 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -64,12 +64,14 @@ func newDummyGitCommand() *GitCommand { func TestVerifyInGitRepo(t *testing.T) { type scenario struct { - runCmd func(string) error - test func(error) + testName string + runCmd func(string) error + test func(error) } scenarios := []scenario{ { + "Valid git repository", func(string) error { return nil }, @@ -78,6 +80,7 @@ func TestVerifyInGitRepo(t *testing.T) { }, }, { + "Not a valid git repository", func(string) error { return fmt.Errorf("fatal: Not a git repository (or any of the parent directories): .git") }, @@ -89,19 +92,23 @@ func TestVerifyInGitRepo(t *testing.T) { } for _, s := range scenarios { - s.test(verifyInGitRepo(s.runCmd)) + t.Run(s.testName, func(t *testing.T) { + s.test(verifyInGitRepo(s.runCmd)) + }) } } func TestNavigateToRepoRootDirectory(t *testing.T) { type scenario struct { - stat func(string) (os.FileInfo, error) - chdir func(string) error - test func(error) + testName string + stat func(string) (os.FileInfo, error) + chdir func(string) error + test func(error) } scenarios := []scenario{ { + "Navigate to git repository", func(string) (os.FileInfo, error) { return fileInfoMock{isDir: true}, nil }, @@ -113,6 +120,7 @@ func TestNavigateToRepoRootDirectory(t *testing.T) { }, }, { + "An error occurred when getting path informations", func(string) (os.FileInfo, error) { return nil, fmt.Errorf("An error occurred") }, @@ -125,18 +133,7 @@ func TestNavigateToRepoRootDirectory(t *testing.T) { }, }, { - func(string) (os.FileInfo, error) { - return nil, os.ErrNotExist - }, - func(string) error { - return fmt.Errorf("An error occurred") - }, - func(err error) { - assert.Error(t, err) - assert.EqualError(t, err, "An error occurred") - }, - }, - { + "An error occurred when trying to move one path backward", func(string) (os.FileInfo, error) { return nil, os.ErrNotExist }, @@ -151,12 +148,15 @@ func TestNavigateToRepoRootDirectory(t *testing.T) { } for _, s := range scenarios { - s.test(navigateToRepoRootDirectory(s.stat, s.chdir)) + t.Run(s.testName, func(t *testing.T) { + s.test(navigateToRepoRootDirectory(s.stat, s.chdir)) + }) } } func TestSetupRepositoryAndWorktree(t *testing.T) { type scenario struct { + testName string openGitRepository func(string) (*gogit.Repository, error) sLocalize func(string) string test func(*gogit.Repository, *gogit.Worktree, error) @@ -164,6 +164,7 @@ func TestSetupRepositoryAndWorktree(t *testing.T) { scenarios := []scenario{ { + "A gitconfig parsing error occurred", func(string) (*gogit.Repository, error) { return nil, fmt.Errorf(`unquoted '\' must be followed by new line`) }, @@ -176,6 +177,7 @@ func TestSetupRepositoryAndWorktree(t *testing.T) { }, }, { + "A gogit error occurred", func(string) (*gogit.Repository, error) { return nil, fmt.Errorf("Error from inside gogit") }, @@ -186,6 +188,7 @@ func TestSetupRepositoryAndWorktree(t *testing.T) { }, }, { + "An error occurred cause git repository is a bare repository", func(string) (*gogit.Repository, error) { return &gogit.Repository{}, nil }, @@ -196,6 +199,7 @@ func TestSetupRepositoryAndWorktree(t *testing.T) { }, }, { + "Setup done properly", func(string) (*gogit.Repository, error) { assert.NoError(t, os.RemoveAll("/tmp/lazygit-test")) r, err := gogit.PlainInit("/tmp/lazygit-test", false) @@ -205,12 +209,16 @@ func TestSetupRepositoryAndWorktree(t *testing.T) { func(string) string { return "" }, func(r *gogit.Repository, w *gogit.Worktree, err error) { assert.NoError(t, err) + assert.NotNil(t, w) + assert.NotNil(t, r) }, }, } for _, s := range scenarios { - s.test(setupRepositoryAndWorktree(s.openGitRepository, s.sLocalize)) + t.Run(s.testName, func(t *testing.T) { + s.test(setupRepositoryAndWorktree(s.openGitRepository, s.sLocalize)) + }) } } @@ -223,12 +231,14 @@ func TestNewGitCommand(t *testing.T) { }() type scenario struct { - setup func() - test func(*GitCommand, error) + testName string + setup func() + test func(*GitCommand, error) } scenarios := []scenario{ { + "An error occurred, folder doesn't contains a git repository", func() { assert.NoError(t, os.Chdir("/tmp")) }, @@ -238,6 +248,7 @@ func TestNewGitCommand(t *testing.T) { }, }, { + "New GitCommand object created", func() { assert.NoError(t, os.RemoveAll("/tmp/lazygit-test")) _, err := gogit.PlainInit("/tmp/lazygit-test", false) @@ -251,19 +262,23 @@ func TestNewGitCommand(t *testing.T) { } for _, s := range scenarios { - s.setup() - s.test(NewGitCommand(newDummyLog(), newDummyOSCommand(), i18n.NewLocalizer(newDummyLog()))) + t.Run(s.testName, func(t *testing.T) { + s.setup() + s.test(NewGitCommand(newDummyLog(), newDummyOSCommand(), i18n.NewLocalizer(newDummyLog()))) + }) } } func TestGitCommandGetStashEntries(t *testing.T) { type scenario struct { - command func(string, ...string) *exec.Cmd - test func([]StashEntry) + testName string + command func(string, ...string) *exec.Cmd + test func([]StashEntry) } scenarios := []scenario{ { + "No stash entries found", func(string, ...string) *exec.Cmd { return exec.Command("echo") }, @@ -272,6 +287,7 @@ func TestGitCommandGetStashEntries(t *testing.T) { }, }, { + "Several stash entries found", func(string, ...string) *exec.Cmd { return exec.Command("echo", "WIP on add-pkg-commands-test: 55c6af2 increase parallel build\nWIP on master: bb86a3f update github template") }, @@ -296,10 +312,12 @@ func TestGitCommandGetStashEntries(t *testing.T) { } for _, s := range scenarios { - gitCmd := newDummyGitCommand() - gitCmd.OSCommand.command = s.command + t.Run(s.testName, func(t *testing.T) { + gitCmd := newDummyGitCommand() + gitCmd.OSCommand.command = s.command - s.test(gitCmd.GetStashEntries()) + s.test(gitCmd.GetStashEntries()) + }) } } @@ -319,12 +337,14 @@ func TestGetStashEntryDiff(t *testing.T) { func TestGetStatusFiles(t *testing.T) { type scenario struct { - command func(string, ...string) *exec.Cmd - test func([]File) + testName string + command func(string, ...string) *exec.Cmd + test func([]File) } scenarios := []scenario{ { + "No files found", func(cmd string, args ...string) *exec.Cmd { return exec.Command("echo") }, @@ -333,6 +353,7 @@ func TestGetStatusFiles(t *testing.T) { }, }, { + "Several files found", func(cmd string, args ...string) *exec.Cmd { return exec.Command( "echo", @@ -391,10 +412,12 @@ func TestGetStatusFiles(t *testing.T) { } for _, s := range scenarios { - gitCmd := newDummyGitCommand() - gitCmd.OSCommand.command = s.command + t.Run(s.testName, func(t *testing.T) { + gitCmd := newDummyGitCommand() + gitCmd.OSCommand.command = s.command - s.test(gitCmd.GetStatusFiles()) + s.test(gitCmd.GetStatusFiles()) + }) } } @@ -437,6 +460,7 @@ func TestGitCommandCommitAmend(t *testing.T) { func TestGitCommandMergeStatusFiles(t *testing.T) { type scenario struct { + testName string oldFiles []File newFiles []File test func([]File) @@ -444,6 +468,7 @@ func TestGitCommandMergeStatusFiles(t *testing.T) { scenarios := []scenario{ { + "Old file and new file are the same", []File{}, []File{ { @@ -462,6 +487,7 @@ func TestGitCommandMergeStatusFiles(t *testing.T) { }, }, { + "Several files to merge, with some identical", []File{ { Name: "new_file1.txt", @@ -504,9 +530,11 @@ func TestGitCommandMergeStatusFiles(t *testing.T) { } for _, s := range scenarios { - gitCmd := newDummyGitCommand() + t.Run(s.testName, func(t *testing.T) { + gitCmd := newDummyGitCommand() - s.test(gitCmd.MergeStatusFiles(s.oldFiles, s.newFiles)) + s.test(gitCmd.MergeStatusFiles(s.oldFiles, s.newFiles)) + }) } } @@ -599,6 +627,8 @@ func TestGitCommandDiff(t *testing.T) { } for _, file := range files { - assert.NotContains(t, gitCommand.Diff(file), "error") + t.Run(file.Name, func(t *testing.T) { + assert.NotContains(t, gitCommand.Diff(file), "error") + }) } } From ceab9706cbfc250e38ecd95d02da19a042ea0d18 Mon Sep 17 00:00:00 2001 From: Anthony HAMON Date: Thu, 6 Sep 2018 22:09:06 +0200 Subject: [PATCH 2/9] commands/git : add tests for UpstreamDifferentCount --- pkg/commands/git_test.go | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index db05e2e07..d8007489a 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -538,6 +538,63 @@ func TestGitCommandMergeStatusFiles(t *testing.T) { } } +func TestGitCommandUpstreamDifferentCount(t *testing.T) { + type scenario struct { + testName string + command func(string, ...string) *exec.Cmd + test func(string, string) + } + + scenarios := []scenario{ + { + "Can't retrieve pushable count", + func(string, ...string) *exec.Cmd { + return exec.Command("exit 1") + }, + func(pushableCount string, pullableCount string) { + assert.EqualValues(t, "?", pushableCount) + assert.EqualValues(t, "?", pullableCount) + }, + }, + { + "Can't retrieve pullable count", + func(cmd string, args ...string) *exec.Cmd { + if args[1] == "head..@{u}" { + return exec.Command("exit 1") + } + + return exec.Command("echo") + }, + func(pushableCount string, pullableCount string) { + assert.EqualValues(t, "?", pushableCount) + assert.EqualValues(t, "?", pullableCount) + }, + }, + { + "Retrieve pullable and pushable count", + func(cmd string, args ...string) *exec.Cmd { + if args[1] == "head..@{u}" { + return exec.Command("echo", "10") + } + + return exec.Command("echo", "11") + }, + func(pushableCount string, pullableCount string) { + assert.EqualValues(t, "11", pushableCount) + assert.EqualValues(t, "10", pullableCount) + }, + }, + } + + for _, s := range scenarios { + t.Run(s.testName, func(t *testing.T) { + gitCmd := newDummyGitCommand() + gitCmd.OSCommand.command = s.command + s.test(gitCmd.UpstreamDifferenceCount()) + }) + } +} + func TestGitCommandDiff(t *testing.T) { gitCommand := newDummyGitCommand() assert.NoError(t, test.GenerateRepo("lots_of_diffs.sh")) From 1ecd74c357101dbedbd2f8afcb81954b281f6e57 Mon Sep 17 00:00:00 2001 From: Anthony HAMON Date: Thu, 6 Sep 2018 23:01:31 +0200 Subject: [PATCH 3/9] commands/git : add tests for GetCommitsToPush --- pkg/commands/git_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index d8007489a..cd0c86198 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -595,6 +595,44 @@ func TestGitCommandUpstreamDifferentCount(t *testing.T) { } } +func TestGitCommandGetCommitsToPush(t *testing.T) { + type scenario struct { + testName string + command func(string, ...string) *exec.Cmd + test func([]string) + } + + scenarios := []scenario{ + { + "Can't retrieve pushable commits", + func(string, ...string) *exec.Cmd { + return exec.Command("exit 1") + }, + func(pushables []string) { + assert.EqualValues(t, []string{}, pushables) + }, + }, + { + "Retrieve pushable commits", + func(cmd string, args ...string) *exec.Cmd { + return exec.Command("echo", "8a2bb0e\n78976bc") + }, + func(pushables []string) { + assert.Len(t, pushables, 2) + assert.EqualValues(t, []string{"8a2bb0e", "78976bc"}, pushables) + }, + }, + } + + for _, s := range scenarios { + t.Run(s.testName, func(t *testing.T) { + gitCmd := newDummyGitCommand() + gitCmd.OSCommand.command = s.command + s.test(gitCmd.GetCommitsToPush()) + }) + } +} + func TestGitCommandDiff(t *testing.T) { gitCommand := newDummyGitCommand() assert.NoError(t, test.GenerateRepo("lots_of_diffs.sh")) From 56ad07ebabd3513e64a073579f9b46563e8f4279 Mon Sep 17 00:00:00 2001 From: Anthony HAMON Date: Thu, 6 Sep 2018 23:05:35 +0200 Subject: [PATCH 4/9] commands/git : rename functions --- pkg/commands/git_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index cd0c86198..ac1fe8094 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -321,7 +321,7 @@ func TestGitCommandGetStashEntries(t *testing.T) { } } -func TestGetStashEntryDiff(t *testing.T) { +func TestGitCommandGetStashEntryDiff(t *testing.T) { gitCmd := newDummyGitCommand() gitCmd.OSCommand.command = func(cmd string, args ...string) *exec.Cmd { assert.EqualValues(t, "git", cmd) @@ -335,7 +335,7 @@ func TestGetStashEntryDiff(t *testing.T) { assert.NoError(t, err) } -func TestGetStatusFiles(t *testing.T) { +func TestGitCommandGetStatusFiles(t *testing.T) { type scenario struct { testName string command func(string, ...string) *exec.Cmd From a0faaf68932b12edb05813751c0c0e80b3e9b48c Mon Sep 17 00:00:00 2001 From: Anthony HAMON Date: Thu, 6 Sep 2018 23:16:56 +0200 Subject: [PATCH 5/9] commands/git : remove includes function --- pkg/commands/git.go | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 61c566780..9f9e65194 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -123,15 +123,6 @@ func (c *GitCommand) GetStashEntryDiff(index int) (string, error) { return c.OSCommand.RunCommandWithOutput("git stash show -p --color stash@{" + fmt.Sprint(index) + "}") } -func includes(array []string, str string) bool { - for _, arrayStr := range array { - if arrayStr == str { - return true - } - } - return false -} - // GetStatusFiles git status files func (c *GitCommand) GetStatusFiles() []File { statusOutput, _ := c.GitStatus() @@ -143,13 +134,15 @@ func (c *GitCommand) GetStatusFiles() []File { stagedChange := change[0:1] unstagedChange := statusString[1:2] filename := c.OSCommand.Unquote(statusString[3:]) - tracked := !includes([]string{"??", "A ", "AM"}, change) + _, untracked := map[string]bool{"??": true, "A ": true, "AM": true}[change] + _, hasUnstagedChanges := map[string]bool{" ": true, "U": true, "?": true}[stagedChange] + file := File{ Name: filename, DisplayString: statusString, - HasStagedChanges: !includes([]string{" ", "U", "?"}, stagedChange), + HasStagedChanges: !hasUnstagedChanges, HasUnstagedChanges: unstagedChange != " ", - Tracked: tracked, + Tracked: !untracked, Deleted: unstagedChange == "D" || stagedChange == "D", HasMergeConflicts: change == "UU", Type: c.OSCommand.FileType(filename), From 99eca7b00048485e22cf3822ecc45e600069da59 Mon Sep 17 00:00:00 2001 From: Anthony HAMON Date: Thu, 6 Sep 2018 23:18:19 +0200 Subject: [PATCH 6/9] commands/git : replace make function --- pkg/commands/git.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 9f9e65194..514967ebd 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -223,7 +223,7 @@ func (c *GitCommand) UpstreamDifferenceCount() (string, string) { func (c *GitCommand) GetCommitsToPush() []string { pushables, err := c.OSCommand.RunCommandWithOutput("git rev-list @{u}..head --abbrev-commit") if err != nil { - return make([]string, 0) + return []string{} } return utils.SplitLines(pushables) } @@ -461,7 +461,7 @@ func includesString(list []string, a string) bool { func (c *GitCommand) GetCommits() []Commit { pushables := c.GetCommitsToPush() log := c.GetLog() - commits := make([]Commit, 0) + commits := []Commit{} // now we can split it up and turn it into commits lines := utils.SplitLines(log) for _, line := range lines { From b46e4b497610aaa771d709f3cab14652e48b8512 Mon Sep 17 00:00:00 2001 From: Anthony HAMON Date: Thu, 6 Sep 2018 23:38:49 +0200 Subject: [PATCH 7/9] commands/git : add several tests, do some cleanup --- pkg/commands/git.go | 18 ++++---- pkg/commands/git_test.go | 97 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 9 deletions(-) diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 514967ebd..fec0bc6ec 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -230,7 +230,7 @@ func (c *GitCommand) GetCommitsToPush() []string { // RenameCommit renames the topmost commit with the given name func (c *GitCommand) RenameCommit(name string) error { - return c.OSCommand.RunCommand("git commit --allow-empty --amend -m " + c.OSCommand.Quote(name)) + return c.OSCommand.RunCommand(fmt.Sprintf("git commit --allow-empty --amend -m %s", c.OSCommand.Quote(name))) } // Fetch fetch git repo @@ -240,23 +240,23 @@ func (c *GitCommand) Fetch() error { // ResetToCommit reset to commit func (c *GitCommand) ResetToCommit(sha string) error { - return c.OSCommand.RunCommand("git reset " + sha) + return c.OSCommand.RunCommand(fmt.Sprintf("git reset %s", sha)) } // NewBranch create new branch func (c *GitCommand) NewBranch(name string) error { - return c.OSCommand.RunCommand("git checkout -b " + name) + return c.OSCommand.RunCommand(fmt.Sprintf("git checkout -b %s", name)) } // DeleteBranch delete branch func (c *GitCommand) DeleteBranch(branch string, force bool) error { - var command string + command := "git branch -d" + if force { - command = "git branch -D " - } else { - command = "git branch -d " + command = "git branch -D" } - return c.OSCommand.RunCommand(command + branch) + + return c.OSCommand.RunCommand(fmt.Sprintf("%s %s", command, branch)) } // ListStash list stash @@ -266,7 +266,7 @@ func (c *GitCommand) ListStash() (string, error) { // Merge merge func (c *GitCommand) Merge(branchName string) error { - return c.OSCommand.RunCommand("git merge --no-edit " + branchName) + return c.OSCommand.RunCommand(fmt.Sprintf("git merge --no-edit %s", branchName)) } // AbortMerge abort merge diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index ac1fe8094..7af75286d 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -633,6 +633,103 @@ func TestGitCommandGetCommitsToPush(t *testing.T) { } } +func TestGitCommandRenameCommit(t *testing.T) { + gitCmd := newDummyGitCommand() + gitCmd.OSCommand.command = func(cmd string, args ...string) *exec.Cmd { + assert.EqualValues(t, "git", cmd) + assert.EqualValues(t, []string{"commit", "--allow-empty", "--amend", "-m", "test"}, args) + + return exec.Command("echo") + } + + assert.NoError(t, gitCmd.RenameCommit("test")) +} + +func TestGitCommandResetToCommit(t *testing.T) { + gitCmd := newDummyGitCommand() + gitCmd.OSCommand.command = func(cmd string, args ...string) *exec.Cmd { + assert.EqualValues(t, "git", cmd) + assert.EqualValues(t, []string{"reset", "78976bc"}, args) + + return exec.Command("echo") + } + + assert.NoError(t, gitCmd.ResetToCommit("78976bc")) +} + +func TestGitCommandNewBranch(t *testing.T) { + gitCmd := newDummyGitCommand() + gitCmd.OSCommand.command = func(cmd string, args ...string) *exec.Cmd { + assert.EqualValues(t, "git", cmd) + assert.EqualValues(t, []string{"checkout", "-b", "test"}, args) + + return exec.Command("echo") + } + + assert.NoError(t, gitCmd.NewBranch("test")) +} + +func TestGitCommandDeleteBranch(t *testing.T) { + type scenario struct { + testName string + branch string + force bool + command func(string, ...string) *exec.Cmd + test func(error) + } + + scenarios := []scenario{ + { + "Delete a branch", + "test", + false, + func(cmd string, args ...string) *exec.Cmd { + assert.EqualValues(t, "git", cmd) + assert.EqualValues(t, []string{"branch", "-d", "test"}, args) + + return exec.Command("echo") + }, + func(err error) { + assert.NoError(t, err) + }, + }, + { + "Force delete a branch", + "test", + true, + func(cmd string, args ...string) *exec.Cmd { + assert.EqualValues(t, "git", cmd) + assert.EqualValues(t, []string{"branch", "-D", "test"}, args) + + return exec.Command("echo") + }, + func(err error) { + assert.NoError(t, err) + }, + }, + } + + for _, s := range scenarios { + t.Run(s.testName, func(t *testing.T) { + gitCmd := newDummyGitCommand() + gitCmd.OSCommand.command = s.command + s.test(gitCmd.DeleteBranch(s.branch, s.force)) + }) + } +} + +func TestGitCommandMerge(t *testing.T) { + gitCmd := newDummyGitCommand() + gitCmd.OSCommand.command = func(cmd string, args ...string) *exec.Cmd { + assert.EqualValues(t, "git", cmd) + assert.EqualValues(t, []string{"merge", "--no-edit", "test"}, args) + + return exec.Command("echo") + } + + assert.NoError(t, gitCmd.Merge("test")) +} + func TestGitCommandDiff(t *testing.T) { gitCommand := newDummyGitCommand() assert.NoError(t, test.GenerateRepo("lots_of_diffs.sh")) From 6076a756432fd1b41d4f1ed297a8a9cdd3570737 Mon Sep 17 00:00:00 2001 From: Anthony HAMON Date: Thu, 6 Sep 2018 23:40:35 +0200 Subject: [PATCH 8/9] commands/git : fix function call --- pkg/commands/git_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index 7af75286d..7bc7a8910 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -549,7 +549,7 @@ func TestGitCommandUpstreamDifferentCount(t *testing.T) { { "Can't retrieve pushable count", func(string, ...string) *exec.Cmd { - return exec.Command("exit 1") + return exec.Command("exit", "1") }, func(pushableCount string, pullableCount string) { assert.EqualValues(t, "?", pushableCount) @@ -560,7 +560,7 @@ func TestGitCommandUpstreamDifferentCount(t *testing.T) { "Can't retrieve pullable count", func(cmd string, args ...string) *exec.Cmd { if args[1] == "head..@{u}" { - return exec.Command("exit 1") + return exec.Command("exit", "1") } return exec.Command("echo") @@ -606,7 +606,7 @@ func TestGitCommandGetCommitsToPush(t *testing.T) { { "Can't retrieve pushable commits", func(string, ...string) *exec.Cmd { - return exec.Command("exit 1") + return exec.Command("exit", "1") }, func(pushables []string) { assert.EqualValues(t, []string{}, pushables) From 24f15742d025eaf8a29b28bf5b426a9af8a33527 Mon Sep 17 00:00:00 2001 From: Anthony HAMON Date: Sun, 9 Sep 2018 20:08:46 +0200 Subject: [PATCH 9/9] commands/git : rename variable --- pkg/commands/git.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/commands/git.go b/pkg/commands/git.go index fec0bc6ec..f7a80dc63 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -135,12 +135,12 @@ func (c *GitCommand) GetStatusFiles() []File { unstagedChange := statusString[1:2] filename := c.OSCommand.Unquote(statusString[3:]) _, untracked := map[string]bool{"??": true, "A ": true, "AM": true}[change] - _, hasUnstagedChanges := map[string]bool{" ": true, "U": true, "?": true}[stagedChange] + _, hasNoStagedChanges := map[string]bool{" ": true, "U": true, "?": true}[stagedChange] file := File{ Name: filename, DisplayString: statusString, - HasStagedChanges: !hasUnstagedChanges, + HasStagedChanges: !hasNoStagedChanges, HasUnstagedChanges: unstagedChange != " ", Tracked: !untracked, Deleted: unstagedChange == "D" || stagedChange == "D",