@@ -455,21 +455,6 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
455
455
return sreconcile .ResultEmpty , e
456
456
}
457
457
458
- repositoryURL := obj .Spec .URL
459
- // managed GIT transport only affects the libgit2 implementation
460
- if managed .Enabled () && obj .Spec .GitImplementation == sourcev1 .LibGit2Implementation {
461
- // We set the TransportAuthID of this set of authentication options here by constructing
462
- // a unique ID that won't clash in a multi tenant environment. This unique ID is used by
463
- // libgit2 managed transports. This enables us to bypass the inbuilt credentials callback in
464
- // libgit2, which is inflexible and unstable.
465
- if strings .HasPrefix (repositoryURL , "http" ) {
466
- authOpts .TransportAuthID = fmt .Sprintf ("http://%s/%s/%d" , obj .Name , obj .UID , obj .Generation )
467
- }
468
- if strings .HasPrefix (repositoryURL , "ssh" ) {
469
- authOpts .TransportAuthID = fmt .Sprintf ("ssh://%s/%s/%d" , obj .Name , obj .UID , obj .Generation )
470
- }
471
- }
472
-
473
458
// Fetch the included artifact metadata.
474
459
artifacts , err := r .fetchIncludes (ctx , obj )
475
460
if err != nil {
@@ -491,7 +476,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
491
476
optimizedClone = true
492
477
}
493
478
494
- c , err := r .gitCheckout (ctx , obj , repositoryURL , authOpts , dir , optimizedClone )
479
+ c , err := r .gitCheckout (ctx , obj , authOpts , dir , optimizedClone )
495
480
if err != nil {
496
481
return sreconcile .ResultEmpty , err
497
482
}
@@ -525,7 +510,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
525
510
526
511
// If we can't skip the reconciliation, checkout again without any
527
512
// optimization.
528
- c , err := r .gitCheckout (ctx , obj , repositoryURL , authOpts , dir , false )
513
+ c , err := r .gitCheckout (ctx , obj , authOpts , dir , false )
529
514
if err != nil {
530
515
return sreconcile .ResultEmpty , err
531
516
}
@@ -717,7 +702,7 @@ func (r *GitRepositoryReconciler) reconcileInclude(ctx context.Context,
717
702
// gitCheckout builds checkout options with the given configurations and
718
703
// performs a git checkout.
719
704
func (r * GitRepositoryReconciler ) gitCheckout (ctx context.Context ,
720
- obj * sourcev1.GitRepository , repoURL string , authOpts * git.AuthOptions , dir string , optimized bool ) (* git.Commit , error ) {
705
+ obj * sourcev1.GitRepository , authOpts * git.AuthOptions , dir string , optimized bool ) (* git.Commit , error ) {
721
706
// Configure checkout strategy.
722
707
checkoutOpts := git.CheckoutOptions {RecurseSubmodules : obj .Spec .RecurseSubmodules }
723
708
if ref := obj .Spec .Reference ; ref != nil {
@@ -743,15 +728,34 @@ func (r *GitRepositoryReconciler) gitCheckout(ctx context.Context,
743
728
Err : fmt .Errorf ("failed to configure checkout strategy for Git implementation '%s': %w" , obj .Spec .GitImplementation , err ),
744
729
Reason : sourcev1 .GitOperationFailedReason ,
745
730
}
746
- conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Err .Error ())
747
731
// Do not return err as recovery without changes is impossible.
748
732
return nil , e
749
733
}
750
734
735
+ // managed GIT transport only affects the libgit2 implementation
736
+ if managed .Enabled () && obj .Spec .GitImplementation == sourcev1 .LibGit2Implementation {
737
+ // We set the TransportOptionsURL of this set of authentication options here by constructing
738
+ // a unique ID that won't clash in a multi tenant environment. This unique ID is used by
739
+ // libgit2 managed transports. This enables us to bypass the inbuilt credentials callback in
740
+ // libgit2, which is inflexible and unstable.
741
+ if strings .HasPrefix (obj .Spec .URL , "http" ) {
742
+ authOpts .TransportOptionsURL = fmt .Sprintf ("http://%s/%s/%d" , obj .Name , obj .UID , obj .Generation )
743
+ } else if strings .HasPrefix (obj .Spec .URL , "ssh" ) {
744
+ authOpts .TransportOptionsURL = fmt .Sprintf ("ssh://%s/%s/%d" , obj .Name , obj .UID , obj .Generation )
745
+ } else {
746
+ e := & serror.Stalling {
747
+ Err : fmt .Errorf ("git repository URL has invalid transport type: '%s'" , obj .Spec .URL ),
748
+ Reason : sourcev1 .GitOperationFailedReason ,
749
+ }
750
+ return nil , e
751
+ }
752
+ }
753
+
751
754
// Checkout HEAD of reference in object
752
755
gitCtx , cancel := context .WithTimeout (ctx , obj .Spec .Timeout .Duration )
753
756
defer cancel ()
754
- commit , err := checkoutStrategy .Checkout (gitCtx , dir , repoURL , authOpts )
757
+
758
+ commit , err := checkoutStrategy .Checkout (gitCtx , dir , obj .Spec .URL , authOpts )
755
759
if err != nil {
756
760
e := serror .NewGeneric (
757
761
fmt .Errorf ("failed to checkout and determine revision: %w" , err ),
0 commit comments