diff options
author | Anthony HAMON <anthony.hamon@iadvize.com> | 2018-08-28 20:18:34 +0200 |
---|---|---|
committer | Anthony HAMON <hamon.anth@gmail.com> | 2018-08-29 12:03:32 +0200 |
commit | 99840d8fc4e4e877f80280272f29394a28699190 (patch) | |
tree | f28f8edb88b80ef5385fa09ed666505a8e339205 /pkg | |
parent | 85012dbc8f8e767076e1ea906eb2498beb6d96bf (diff) |
add test for StashDo and refactor StashDo method
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/commands/git.go | 2 | ||||
-rw-r--r-- | pkg/commands/git_test.go | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index d02d75b4f..9b3c72fd9 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -106,7 +106,7 @@ func (c *GitCommand) GetStatusFiles() []File { // StashDo modify stash func (c *GitCommand) StashDo(index int, method string) error { - return c.OSCommand.RunCommand("git stash " + method + " stash@{" + fmt.Sprint(index) + "}") + return c.OSCommand.RunCommand(fmt.Sprintf("git stash %s stash@{%d}", method, index)) } // StashSave save stash diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index f77c2a3b9..554ffbd1a 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -161,6 +161,18 @@ func TestGetStatusFiles(t *testing.T) { } } +func TestGitCommandStashDo(t *testing.T) { + gitCmd := newDummyGitCommand() + gitCmd.OSCommand.command = func(cmd string, args ...string) *exec.Cmd { + assert.EqualValues(t, "git", cmd) + assert.EqualValues(t, []string{"stash", "drop", "stash@{1}"}, args) + + return exec.Command("echo") + } + + assert.NoError(t, gitCmd.StashDo(1, "drop")) +} + func TestGitCommandDiff(t *testing.T) { gitCommand := newDummyGitCommand() assert.NoError(t, test.GenerateRepo("lots_of_diffs.sh")) |