summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorAnthony HAMON <hamon.anth@gmail.com>2018-09-04 06:16:19 +0200
committerAnthony HAMON <hamon.anth@gmail.com>2018-09-04 08:32:40 +0200
commitdf3e7abd688d17982d477f67e05670cacdff4bb4 (patch)
tree4f411f8d4b5421a4bd2cbbb854665d114df52a37 /pkg
parent8c675780639ffb1f214c7fcfaa34c09862ccd092 (diff)
use RunCommand
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/git.go14
-rw-r--r--pkg/commands/git_test.go18
2 files changed, 12 insertions, 20 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index df78a2e3a..61c566780 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -15,16 +15,8 @@ import (
gogit "gopkg.in/src-d/go-git.v4"
)
-// ErrGitRepositoryInvalid is emitted when we run a git command in a folder
-// to check if we have a valid git repository and we get an error instead
-var ErrGitRepositoryInvalid = errors.New("can't find a valid git repository in current directory")
-
-func verifyInGitRepo(runCmdWithOutput func(string) (string, error)) error {
- if _, err := runCmdWithOutput("git status"); err != nil {
- return ErrGitRepositoryInvalid
- }
-
- return nil
+func verifyInGitRepo(runCmd func(string) error) error {
+ return runCmd("git status")
}
func navigateToRepoRootDirectory(stat func(string) (os.FileInfo, error), chdir func(string) error) error {
@@ -81,7 +73,7 @@ func NewGitCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Localizer)
fs := []func() error{
func() error {
- return verifyInGitRepo(osCommand.RunCommandWithOutput)
+ return verifyInGitRepo(osCommand.RunCommand)
},
func() error {
return navigateToRepoRootDirectory(os.Stat, os.Chdir)
diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go
index 64d3828ea..777eebaec 100644
--- a/pkg/commands/git_test.go
+++ b/pkg/commands/git_test.go
@@ -64,32 +64,32 @@ func newDummyGitCommand() *GitCommand {
func TestVerifyInGitRepo(t *testing.T) {
type scenario struct {
- runCmdWithOutput func(string) (string, error)
- test func(error)
+ runCmd func(string) error
+ test func(error)
}
scenarios := []scenario{
{
- func(string) (string, error) {
- return "", nil
+ func(string) error {
+ return nil
},
func(err error) {
assert.NoError(t, err)
},
},
{
- func(string) (string, error) {
- return "", ErrGitRepositoryInvalid
+ func(string) error {
+ return fmt.Errorf("fatal: Not a git repository (or any of the parent directories): .git")
},
func(err error) {
assert.Error(t, err)
- assert.Equal(t, ErrGitRepositoryInvalid, err)
+ assert.Regexp(t, "fatal: .ot a git repository \\(or any of the parent directories\\): \\.git", err.Error())
},
},
}
for _, s := range scenarios {
- s.test(verifyInGitRepo(s.runCmdWithOutput))
+ s.test(verifyInGitRepo(s.runCmd))
}
}
@@ -234,7 +234,7 @@ func TestNewGitCommand(t *testing.T) {
},
func(gitCmd *GitCommand, err error) {
assert.Error(t, err)
- assert.Equal(t, ErrGitRepositoryInvalid, err)
+ assert.Regexp(t, "fatal: .ot a git repository \\(or any of the parent directories\\): \\.git", err.Error())
},
},
{