From e2457fd27f6239af82c2c132fbc1c58b73bbe362 Mon Sep 17 00:00:00 2001 From: Ross Light Date: Fri, 28 Jul 2023 12:59:42 -0700 Subject: [PATCH] git: return 0 from exitCode if err == nil --- exit.go | 8 ++++++-- exit_test.go | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/exit.go b/exit.go index 693fbb2..1ebf400 100644 --- a/exit.go +++ b/exit.go @@ -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 } diff --git a/exit_test.go b/exit_test.go index 5cc1004..a0a5bd8 100644 --- a/exit_test.go +++ b/exit_test.go @@ -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 {