@@ -600,6 +600,7 @@ func TestGitRepositoryReconciler_reconcileSource_checkoutStrategy(t *testing.T)
600
600
601
601
branches := []string {"staging" }
602
602
tags := []string {"non-semver-tag" , "v0.1.0" , "0.2.0" , "v0.2.1" , "v1.0.0-alpha" , "v1.1.0" , "v2.0.0" }
603
+ refs := []string {"refs/pull/420/head" }
603
604
604
605
tests := []struct {
605
606
name string
@@ -645,6 +646,24 @@ func TestGitRepositoryReconciler_reconcileSource_checkoutStrategy(t *testing.T)
645
646
wantRevision : "staging@sha1:<commit>" ,
646
647
wantReconciling : true ,
647
648
},
649
+ {
650
+ name : "Ref Name pointing to a branch" ,
651
+ reference : & sourcev1.GitRepositoryRef {
652
+ Name : "refs/heads/staging" ,
653
+ },
654
+ want : sreconcile .ResultSuccess ,
655
+ wantRevision : "refs/heads/staging@sha1:<commit>" ,
656
+ wantReconciling : true ,
657
+ },
658
+ {
659
+ name : "Ref Name pointing to a PR" ,
660
+ reference : & sourcev1.GitRepositoryRef {
661
+ Name : "refs/pull/420/head" ,
662
+ },
663
+ want : sreconcile .ResultSuccess ,
664
+ wantRevision : "refs/pull/420/head@sha1:<commit>" ,
665
+ wantReconciling : true ,
666
+ },
648
667
{
649
668
name : "SemVer" ,
650
669
reference : & sourcev1.GitRepositoryRef {
@@ -801,6 +820,10 @@ func TestGitRepositoryReconciler_reconcileSource_checkoutStrategy(t *testing.T)
801
820
g .Expect (remoteTagForHead (localRepo , headRef , tag )).To (Succeed ())
802
821
}
803
822
823
+ for _ , ref := range refs {
824
+ g .Expect (remoteRefForHead (localRepo , headRef , ref )).To (Succeed ())
825
+ }
826
+
804
827
r := & GitRepositoryReconciler {
805
828
Client : fakeclient .NewClientBuilder ().WithScheme (testEnv .GetScheme ()).Build (),
806
829
EventRecorder : record .NewFakeRecorder (32 ),
@@ -854,7 +877,7 @@ func TestGitRepositoryReconciler_reconcileSource_checkoutStrategy(t *testing.T)
854
877
g .Expect (got ).To (Equal (tt .want ))
855
878
if tt .wantRevision != "" && ! tt .wantErr {
856
879
revision := strings .ReplaceAll (tt .wantRevision , "<commit>" , headRef .Hash ().String ())
857
- g .Expect (commit . String ( )).To (Equal (revision ))
880
+ g .Expect (commitReference ( obj , & commit )).To (Equal (revision ))
858
881
g .Expect (conditions .IsTrue (obj , sourcev1 .ArtifactOutdatedCondition )).To (Equal (tt .wantArtifactOutdated ))
859
882
g .Expect (conditions .IsTrue (obj , meta .ReconcilingCondition )).To (Equal (tt .wantReconciling ))
860
883
}
@@ -1888,6 +1911,20 @@ func remoteTagForHead(repo *gogit.Repository, head *plumbing.Reference, tag stri
1888
1911
})
1889
1912
}
1890
1913
1914
+ func remoteRefForHead (repo * gogit.Repository , head * plumbing.Reference , reference string ) error {
1915
+ if err := repo .Storer .SetReference (plumbing .NewHashReference (plumbing .ReferenceName (reference ), head .Hash ())); err != nil {
1916
+ return err
1917
+ }
1918
+ if err := repo .Push (& gogit.PushOptions {
1919
+ RefSpecs : []config.RefSpec {
1920
+ config .RefSpec ("+" + reference + ":" + reference ),
1921
+ },
1922
+ }); err != nil {
1923
+ return err
1924
+ }
1925
+ return nil
1926
+ }
1927
+
1891
1928
func TestGitRepositoryReconciler_statusConditions (t * testing.T ) {
1892
1929
tests := []struct {
1893
1930
name string
0 commit comments