diff options
author | Anthony HAMON <hamon.anth@gmail.com> | 2018-09-18 20:53:32 +0200 |
---|---|---|
committer | Anthony HAMON <hamon.anth@gmail.com> | 2018-09-20 09:09:37 +0200 |
commit | bdeb78c9a04963847ffd90c2277b3a274e3ba309 (patch) | |
tree | d1a754e857836a156e6180a9d35323595c53689c /pkg | |
parent | 9481920101c7f8e29875e6db2642fe2b317564f9 (diff) |
commands/git : returns an error instead of panicing
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/commands/git.go | 8 | ||||
-rw-r--r-- | pkg/commands/git_test.go | 13 | ||||
-rw-r--r-- | pkg/gui/commits_panel.go | 5 |
3 files changed, 19 insertions, 7 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index c37ca9b47..24dcc6894 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -499,12 +499,8 @@ func (c *GitCommand) Ignore(filename string) error { } // Show shows the diff of a commit -func (c *GitCommand) Show(sha string) string { - result, err := c.OSCommand.RunCommandWithOutput("git show --color " + sha) - if err != nil { - panic(err) - } - return result +func (c *GitCommand) Show(sha string) (string, error) { + return c.OSCommand.RunCommandWithOutput(fmt.Sprintf("git show --color %s", sha)) } // Diff returns the diff of a file diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index ba2696e5d..eb17103fc 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -1421,6 +1421,19 @@ func TestGitCommandRemoveFile(t *testing.T) { } } +func TestGitCommandShow(t *testing.T) { + gitCmd := newDummyGitCommand() + gitCmd.OSCommand.command = func(cmd string, args ...string) *exec.Cmd { + assert.EqualValues(t, "git", cmd) + assert.EqualValues(t, []string{"show", "--color", "456abcde"}, args) + + return exec.Command("echo") + } + + _, err := gitCmd.Show("456abcde") + assert.NoError(t, err) +} + func TestGitCommandCheckout(t *testing.T) { type scenario struct { testName string diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index 7c09559ff..91bb334ff 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -68,7 +68,10 @@ func (gui *Gui) handleCommitSelect(g *gocui.Gui, v *gocui.View) error { } return gui.renderString(g, "main", gui.Tr.SLocalize("NoCommitsThisBranch")) } - commitText := gui.GitCommand.Show(commit.Sha) + commitText, err := gui.GitCommand.Show(commit.Sha) + if err != nil { + return err + } return gui.renderString(g, "main", commitText) } |