diff --git a/git/client.go b/git/client.go index 820a9cdc7..19688ca51 100644 --- a/git/client.go +++ b/git/client.go @@ -392,12 +392,10 @@ func (c *Client) ReadBranchConfig(ctx context.Context, branch string) (BranchCon out, err := cmd.Output() if err != nil { // This is the error we expect if the git command does not run successfully. - // Note: err is non-nil if the command is successful but has no output + // If the ExitCode is 1, then we just didn't find any config for the branch. var gitError *GitError - if errors.As(err, &gitError) { - if gitError.Stderr != "" { - return BranchConfig{}, err - } + if ok := errors.As(err, &gitError); ok && gitError.ExitCode != 1 { + return BranchConfig{}, err } return BranchConfig{}, nil } diff --git a/git/client_test.go b/git/client_test.go index 94d1c3969..fe3047db9 100644 --- a/git/client_test.go +++ b/git/client_test.go @@ -744,16 +744,7 @@ func TestClientReadBranchConfig(t *testing.T) { wantError: nil, }, { - name: "output error", - cmdExitStatus: 1, - cmdStdout: "", - cmdStderr: "git error message", - branch: "trunk", - wantBranchConfig: BranchConfig{}, - wantError: &GitError{}, - }, - { - name: "git config runs successfully but returns no output", + name: "git config runs successfully but returns no output (Exit Code 1)", cmdExitStatus: 1, cmdStdout: "", cmdStderr: "", @@ -761,6 +752,15 @@ func TestClientReadBranchConfig(t *testing.T) { wantBranchConfig: BranchConfig{}, wantError: nil, }, + { + name: "output error (Exit Code > 1)", + cmdExitStatus: 2, + cmdStdout: "", + cmdStderr: "git error message", + branch: "trunk", + wantBranchConfig: BranchConfig{}, + wantError: &GitError{}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {