@@ -422,8 +422,13 @@ func (r *GitRepositoryReconciler) reconcileStorage(ctx context.Context,
422422// change, it short-circuits the whole reconciliation with an early return.
423423func (r * GitRepositoryReconciler ) reconcileSource (ctx context.Context ,
424424 obj * sourcev1.GitRepository , commit * git.Commit , includes * artifactSet , dir string ) (sreconcile.Result , error ) {
425+ gitImplementation := obj .Spec .GitImplementation
426+ if goGitOnly , _ := r .features [features .ForceGoGitImplementation ]; goGitOnly {
427+ gitImplementation = sourcev1 .GoGitImplementation
428+ }
429+
425430 // Exit early, if we need to use libgit2 AND managed transport hasn't been intialized.
426- if ! r .Libgit2TransportInitialized () && obj . Spec . GitImplementation == sourcev1 .LibGit2Implementation {
431+ if ! r .Libgit2TransportInitialized () && gitImplementation == sourcev1 .LibGit2Implementation {
427432 return sreconcile .ResultEmpty , serror .NewStalling (
428433 errors .New ("libgit2 managed transport not initialized" ), "Libgit2TransportNotEnabled" ,
429434 )
@@ -499,7 +504,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
499504 optimizedClone = true
500505 }
501506
502- c , err := r .gitCheckout (ctx , obj , authOpts , dir , optimizedClone )
507+ c , err := r .gitCheckout (ctx , obj , authOpts , dir , optimizedClone , gitImplementation )
503508 if err != nil {
504509 return sreconcile .ResultEmpty , err
505510 }
@@ -533,7 +538,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
533538
534539 // If we can't skip the reconciliation, checkout again without any
535540 // optimization.
536- c , err := r .gitCheckout (ctx , obj , authOpts , dir , false )
541+ c , err := r .gitCheckout (ctx , obj , authOpts , dir , false , gitImplementation )
537542 if err != nil {
538543 return sreconcile .ResultEmpty , err
539544 }
@@ -725,7 +730,8 @@ func (r *GitRepositoryReconciler) reconcileInclude(ctx context.Context,
725730// gitCheckout builds checkout options with the given configurations and
726731// performs a git checkout.
727732func (r * GitRepositoryReconciler ) gitCheckout (ctx context.Context ,
728- obj * sourcev1.GitRepository , authOpts * git.AuthOptions , dir string , optimized bool ) (* git.Commit , error ) {
733+ obj * sourcev1.GitRepository , authOpts * git.AuthOptions , dir string ,
734+ optimized bool , gitImplementation string ) (* git.Commit , error ) {
729735 // Configure checkout strategy.
730736 cloneOpts := git.CloneOptions {
731737 RecurseSubmodules : obj .Spec .RecurseSubmodules ,
@@ -753,18 +759,18 @@ func (r *GitRepositoryReconciler) gitCheckout(ctx context.Context,
753759 var gitReader git.RepositoryReader
754760 var err error
755761
756- switch obj . Spec . GitImplementation {
762+ switch gitImplementation {
757763 case sourcev1 .LibGit2Implementation :
758764 gitReader , err = libgit2 .NewClient (dir , authOpts )
759765 case sourcev1 .GoGitImplementation :
760766 gitReader , err = gogit .NewClient (dir , authOpts )
761767 default :
762- err = fmt .Errorf ("invalid Git implementation: %s" , obj . Spec . GitImplementation )
768+ err = fmt .Errorf ("invalid Git implementation: %s" , gitImplementation )
763769 }
764770 if err != nil {
765771 // Do not return err as recovery without changes is impossible.
766772 e := serror .NewStalling (
767- fmt .Errorf ("failed to create Git client for implementation '%s': %w" , obj . Spec . GitImplementation , err ),
773+ fmt .Errorf ("failed to create Git client for implementation '%s': %w" , gitImplementation , err ),
768774 sourcev1 .GitOperationFailedReason ,
769775 )
770776 conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Err .Error ())
0 commit comments