@@ -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,18 +790,18 @@ 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
+ func (r * Repository ) cloneRefSpec (o * CloneOptions ) []config.RefSpec {
793
794
var rs string
794
795
795
796
switch {
796
797
case o .ReferenceName .IsTag ():
797
798
rs = fmt .Sprintf (refspecTag , o .ReferenceName .Short ())
798
799
case o .SingleBranch && o .ReferenceName == plumbing .HEAD :
799
- rs = fmt .Sprintf (refspecSingleBranchHEAD , c . Name )
800
+ rs = fmt .Sprintf (refspecSingleBranchHEAD , o . RemoteName )
800
801
case o .SingleBranch :
801
- rs = fmt .Sprintf (refspecSingleBranch , o .ReferenceName .Short (), c . Name )
802
+ rs = fmt .Sprintf (refspecSingleBranch , o .ReferenceName .Short (), o . RemoteName )
802
803
default :
803
- return c . Fetch
804
+ return []config. RefSpec { config . RefSpec ( fmt . Sprintf ( config . DefaultFetchRefSpec , o . RemoteName ))}
804
805
}
805
806
806
807
return []config.RefSpec {config .RefSpec (rs )}
@@ -821,9 +822,11 @@ func (r *Repository) updateRemoteConfigIfNeeded(o *CloneOptions, c *config.Remot
821
822
return nil
822
823
}
823
824
824
- c .Fetch = []config.RefSpec {config .RefSpec (fmt .Sprintf (
825
- refspecSingleBranch , head .Name ().Short (), c .Name ,
826
- ))}
825
+ if err := o .Validate (); err != nil {
826
+ return err
827
+ }
828
+
829
+ c .Fetch = r .cloneRefSpec (o )
827
830
828
831
cfg , err := r .Storer .Config ()
829
832
if err != nil {
0 commit comments