Skip to content

Commit 175f91e

Browse files
author
Sanskar Jaiswal
committed
recover from panics in cloneInto
Signed-off-by: Sanskar Jaiswal <[email protected]>
1 parent 61f76d3 commit 175f91e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

controllers/imageupdateautomation_controller.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,12 +541,15 @@ func (r repoAccess) remoteCallbacks(ctx context.Context) libgit2.RemoteCallbacks
541541
// cloneInto clones the upstream repository at the `ref` given (which
542542
// can be `nil`). It returns a `*libgit2.Repository` since that is used
543543
// for committing changes.
544-
func cloneInto(ctx context.Context, access repoAccess, ref *sourcev1.GitRepositoryRef, path string) (*libgit2.Repository, error) {
544+
func cloneInto(ctx context.Context, access repoAccess, ref *sourcev1.GitRepositoryRef,
545+
path string) (_ *libgit2.Repository, err error) {
546+
defer recoverPanic(&err)
547+
545548
opts := git.CheckoutOptions{}
546549
if ref != nil {
547550
opts.Tag = ref.Tag
548551
opts.SemVer = ref.SemVer
549-
opts.Tag = ref.Tag
552+
opts.Commit = ref.Commit
550553
opts.Branch = ref.Branch
551554
}
552555
checkoutStrat, err := gitstrat.CheckoutStrategyForImplementation(ctx, sourcev1.LibGit2Implementation, opts)
@@ -980,3 +983,9 @@ func templateMsg(messageTemplate string, templateValues *TemplateData) (string,
980983
}
981984
return b.String(), nil
982985
}
986+
987+
func recoverPanic(err *error) {
988+
if r := recover(); r != nil {
989+
*err = fmt.Errorf("recovered from git2go panic: %v", r)
990+
}
991+
}

0 commit comments

Comments
 (0)