@@ -50,6 +50,7 @@ import (
5050 "github.com/fluxcd/source-controller/internal/reconcile/summarize"
5151 "github.com/fluxcd/source-controller/internal/util"
5252 "github.com/fluxcd/source-controller/pkg/git"
53+ "github.com/fluxcd/source-controller/pkg/git/libgit2/managed"
5354 "github.com/fluxcd/source-controller/pkg/git/strategy"
5455 "github.com/fluxcd/source-controller/pkg/sourceignore"
5556)
@@ -369,10 +370,37 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
369370 return sreconcile .ResultEmpty , e
370371 }
371372
373+ repositoryURL := obj .Spec .URL
374+ // managed GIT transport only affects the libgit2 implementation
375+ if managed .Enabled () && obj .Spec .GitImplementation == sourcev1 .LibGit2Implementation {
376+ // At present only HTTP connections have the ability to define remote options.
377+ // Although this can be easily extended by ensuring that the fake URL below uses the
378+ // target ssh scheme, and the libgit2/managed/ssh.go pulls that information accordingly.
379+ //
380+ // This is due to the fact the key libgit2 remote callbacks do not take place for HTTP
381+ // whilst most still work for SSH.
382+ if strings .HasPrefix (repositoryURL , "http" ) {
383+ // Due to the lack of the callback feature, a fake target URL is created to allow
384+ // for the smart sub transport be able to pick the options specific for this
385+ // GitRepository object.
386+ // The URL should use unique information that do not collide in a multi tenant
387+ // deployment.
388+ repositoryURL = fmt .Sprintf ("http://%s/%s/%d" , obj .Name , obj .UID , obj .Generation )
389+ managed .AddTransportOptions (repositoryURL ,
390+ managed.TransportOptions {
391+ TargetURL : obj .Spec .URL ,
392+ CABundle : authOpts .CAFile ,
393+ })
394+
395+ // We remove the options from memory, to avoid accumulating unused options over time.
396+ defer managed .RemoveTransportOptions (repositoryURL )
397+ }
398+ }
399+
372400 // Checkout HEAD of reference in object
373401 gitCtx , cancel := context .WithTimeout (ctx , obj .Spec .Timeout .Duration )
374402 defer cancel ()
375- c , err := checkoutStrategy .Checkout (gitCtx , dir , obj . Spec . URL , authOpts )
403+ c , err := checkoutStrategy .Checkout (gitCtx , dir , repositoryURL , authOpts )
376404 if err != nil {
377405 e := & serror.Event {
378406 Err : fmt .Errorf ("failed to checkout and determine revision: %w" , err ),
0 commit comments