Skip to content

Commit

Permalink
git: return 0 from exitCode if err == nil
Browse files Browse the repository at this point in the history
  • Loading branch information
zombiezen committed Jul 28, 2023
1 parent aa36f26 commit e2457fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ package git

import "errors"

// exitCode returns the exit code indicated by the error, or -1 if the error
// doesn't indicate an exited process.
// exitCode returns the exit code indicated by the error,
// zero if the error is nil,
// or -1 if the error doesn't indicate an exited process.
func exitCode(err error) int {
if err == nil {
return 0
}
var coder interface {
ExitCode() int
}
Expand Down
4 changes: 4 additions & 0 deletions exit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func TestExitCode(t *testing.T) {
err: errors.New("bork"),
want: -1,
},
{
err: nil,
want: 0,
},
}
for _, test := range tests {
if got := exitCode(test.err); got != test.want {
Expand Down

0 comments on commit e2457fd

Please sign in to comment.