@@ -141,12 +141,7 @@ func (r *GitRepositoryReconciler) SetupWithManagerAndOptions(mgr ctrl.Manager, o
141141 r .requeueDependency = opts .DependencyRequeueInterval
142142
143143 if r .features == nil {
144- r .features = map [string ]bool {}
145- }
146-
147- // Check and enable gated features.
148- if oc , _ := features .Enabled (features .OptimizedGitClones ); oc {
149- r .features [features .OptimizedGitClones ] = true
144+ r .features = features .FeatureGates ()
150145 }
151146
152147 return ctrl .NewControllerManagedBy (mgr ).
@@ -427,8 +422,13 @@ func (r *GitRepositoryReconciler) reconcileStorage(ctx context.Context,
427422// change, it short-circuits the whole reconciliation with an early return.
428423func (r * GitRepositoryReconciler ) reconcileSource (ctx context.Context ,
429424 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+
430430 // Exit early, if we need to use libgit2 AND managed transport hasn't been intialized.
431- if ! r .Libgit2TransportInitialized () && obj . Spec . GitImplementation == sourcev1 .LibGit2Implementation {
431+ if ! r .Libgit2TransportInitialized () && gitImplementation == sourcev1 .LibGit2Implementation {
432432 return sreconcile .ResultEmpty , serror .NewStalling (
433433 errors .New ("libgit2 managed transport not initialized" ), "Libgit2TransportNotEnabled" ,
434434 )
@@ -504,7 +504,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
504504 optimizedClone = true
505505 }
506506
507- c , err := r .gitCheckout (ctx , obj , authOpts , dir , optimizedClone )
507+ c , err := r .gitCheckout (ctx , obj , authOpts , dir , optimizedClone , gitImplementation )
508508 if err != nil {
509509 return sreconcile .ResultEmpty , err
510510 }
@@ -538,7 +538,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
538538
539539 // If we can't skip the reconciliation, checkout again without any
540540 // optimization.
541- c , err := r .gitCheckout (ctx , obj , authOpts , dir , false )
541+ c , err := r .gitCheckout (ctx , obj , authOpts , dir , false , gitImplementation )
542542 if err != nil {
543543 return sreconcile .ResultEmpty , err
544544 }
@@ -730,7 +730,8 @@ func (r *GitRepositoryReconciler) reconcileInclude(ctx context.Context,
730730// gitCheckout builds checkout options with the given configurations and
731731// performs a git checkout.
732732func (r * GitRepositoryReconciler ) gitCheckout (ctx context.Context ,
733- 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 ) {
734735 // Configure checkout strategy.
735736 cloneOpts := git.CloneOptions {
736737 RecurseSubmodules : obj .Spec .RecurseSubmodules ,
@@ -758,18 +759,17 @@ func (r *GitRepositoryReconciler) gitCheckout(ctx context.Context,
758759 var gitReader git.RepositoryReader
759760 var err error
760761
761- switch obj . Spec . GitImplementation {
762+ switch gitImplementation {
762763 case sourcev1 .LibGit2Implementation :
763764 gitReader , err = libgit2 .NewClient (dir , authOpts )
764765 case sourcev1 .GoGitImplementation :
765766 gitReader , err = gogit .NewClient (dir , authOpts )
766767 default :
767- err = fmt .Errorf ("invalid Git implementation: %s" , obj . Spec . GitImplementation )
768+ err = fmt .Errorf ("invalid Git implementation: %s" , gitImplementation )
768769 }
769770 if err != nil {
770- // Do not return err as recovery without changes is impossible.
771- e := serror .NewStalling (
772- fmt .Errorf ("failed to create Git client for implementation '%s': %w" , obj .Spec .GitImplementation , err ),
771+ e := serror .NewGeneric (
772+ fmt .Errorf ("failed to create Git client for implementation '%s': %w" , gitImplementation , err ),
773773 sourcev1 .GitOperationFailedReason ,
774774 )
775775 conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Err .Error ())
0 commit comments