diff --git a/pkg/cmd/auth/gitcredential/helper.go b/pkg/cmd/auth/gitcredential/helper.go index 46d05d92c..759025f16 100644 --- a/pkg/cmd/auth/gitcredential/helper.go +++ b/pkg/cmd/auth/gitcredential/helper.go @@ -54,7 +54,12 @@ func NewCmdCredential(f *cmdutil.Factory, runF func(*CredentialOptions) error) * func helperRun(opts *CredentialOptions) error { if opts.Operation == "store" { // We pretend to implement the "store" operation, but do nothing since we already have a cached token. - return cmdutil.SilentError + return nil + } + + if opts.Operation == "erase" { + // We pretend to implement the "erase" operation, but do nothing since we don't want git to cause user to be logged out. + return nil } if opts.Operation != "get" { diff --git a/pkg/cmd/auth/gitcredential/helper_test.go b/pkg/cmd/auth/gitcredential/helper_test.go index c1f76e6fa..b80e77b86 100644 --- a/pkg/cmd/auth/gitcredential/helper_test.go +++ b/pkg/cmd/auth/gitcredential/helper_test.go @@ -218,6 +218,25 @@ func Test_helperRun(t *testing.T) { `), wantStderr: "", }, + { + name: "noop store operation", + opts: CredentialOptions{ + Operation: "store", + }, + }, + { + name: "noop erase operation", + opts: CredentialOptions{ + Operation: "erase", + }, + }, + { + name: "unknown operation", + opts: CredentialOptions{ + Operation: "unknown", + }, + wantErr: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {