@@ -710,16 +710,17 @@ func (r *Repository) clone(ctx context.Context, o *CloneOptions) error {
710
710
}
711
711
712
712
c := & config.RemoteConfig {
713
- Name : o .RemoteName ,
714
- URLs : []string {o .URL },
713
+ Name : o .RemoteName ,
714
+ URLs : []string {o .URL },
715
+ Fetch : r .cloneRefSpec (o ),
715
716
}
716
717
717
718
if _ , err := r .CreateRemote (c ); err != nil {
718
719
return err
719
720
}
720
721
721
722
ref , err := r .fetchAndUpdateReferences (ctx , & FetchOptions {
722
- RefSpecs : r . cloneRefSpec ( o , c ) ,
723
+ RefSpecs : c . Fetch ,
723
724
Depth : o .Depth ,
724
725
Auth : o .Auth ,
725
726
Progress : o .Progress ,
@@ -789,21 +790,24 @@ const (
789
790
refspecSingleBranchHEAD = "+HEAD:refs/remotes/%s/HEAD"
790
791
)
791
792
792
- func (r * Repository ) cloneRefSpec (o * CloneOptions , c * config.RemoteConfig ) []config.RefSpec {
793
- var rs string
794
-
793
+ func (r * Repository ) cloneRefSpec (o * CloneOptions ) []config.RefSpec {
795
794
switch {
796
795
case o .ReferenceName .IsTag ():
797
- rs = fmt .Sprintf (refspecTag , o .ReferenceName .Short ())
796
+ return []config.RefSpec {
797
+ config .RefSpec (fmt .Sprintf (refspecTag , o .ReferenceName .Short ())),
798
+ }
798
799
case o .SingleBranch && o .ReferenceName == plumbing .HEAD :
799
- rs = fmt .Sprintf (refspecSingleBranchHEAD , c .Name )
800
+ return []config.RefSpec {
801
+ config .RefSpec (fmt .Sprintf (refspecSingleBranch , o .ReferenceName .Short (), o .RemoteName )),
802
+ config .RefSpec (fmt .Sprintf (refspecSingleBranchHEAD , o .RemoteName )),
803
+ }
800
804
case o .SingleBranch :
801
- rs = fmt .Sprintf (refspecSingleBranch , o .ReferenceName .Short (), c .Name )
805
+ return []config.RefSpec {
806
+ config .RefSpec (fmt .Sprintf (refspecSingleBranch , o .ReferenceName .Short (), o .RemoteName )),
807
+ }
802
808
default :
803
- return c . Fetch
809
+ return []config. RefSpec {}
804
810
}
805
-
806
- return []config.RefSpec {config .RefSpec (rs )}
807
811
}
808
812
809
813
func (r * Repository ) setIsBare (isBare bool ) error {
0 commit comments