diff --git a/git/command.go b/git/command.go index b68b59525..8065ffd86 100644 --- a/git/command.go +++ b/git/command.go @@ -6,7 +6,6 @@ import ( "errors" "io" "os/exec" - "strings" "github.com/cli/cli/v2/internal/run" ) @@ -49,10 +48,6 @@ func (gc *Command) Output() ([]byte, error) { ge.Stderr = string(exitError.Stderr) ge.ExitCode = exitError.ExitCode() } - - if strings.Contains(ge.Stderr, "fatal: not a git repository") { - ge.err = ErrNoGitRepository - } err = &ge } return out, err diff --git a/git/command_test.go b/git/command_test.go index 15fd291fc..033492e01 100644 --- a/git/command_test.go +++ b/git/command_test.go @@ -18,7 +18,7 @@ func TestOutput(t *testing.T) { exitCode int stdout string stderr string - wantErr error + wantErr *GitError }{ { name: "successful command", @@ -32,7 +32,11 @@ func TestOutput(t *testing.T) { stdout: "", stderr: "fatal: not a git repository (or any of the parent directories): .git", exitCode: 128, - wantErr: ErrNoGitRepository, + wantErr: &GitError{ + ExitCode: 128, + Stderr: "fatal: not a git repository (or any of the parent directories): .git", + err: &exec.ExitError{}, + }, }, } @@ -50,7 +54,9 @@ func TestOutput(t *testing.T) { require.Error(t, err) var gitError *GitError require.ErrorAs(t, err, &gitError) - assert.Equal(t, tt.wantErr, gitError.err) + assert.Equal(t, tt.wantErr.ExitCode, gitError.ExitCode) + assert.Equal(t, tt.wantErr.Stderr, gitError.Stderr) + assert.Equal(t, tt.wantErr.Error(), gitError.Error()) } else { require.NoError(t, err) } diff --git a/git/errors.go b/git/errors.go index 9d433e906..a3f1645aa 100644 --- a/git/errors.go +++ b/git/errors.go @@ -7,7 +7,6 @@ import ( // ErrNotOnAnyBranch indicates that the user is in detached HEAD state. var ErrNotOnAnyBranch = errors.New("git: not on any branch") -var ErrNoGitRepository = errors.New("git: not in a git repository") type NotInstalled struct { message string