Skip to content

Commit 4343ef9

Browse files
committed
Fix RefSpec for a single tag
Fixes src-d#960
1 parent 959dc01 commit 4343ef9

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

repository.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -710,16 +710,17 @@ func (r *Repository) clone(ctx context.Context, o *CloneOptions) error {
710710
}
711711

712712
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),
715716
}
716717

717718
if _, err := r.CreateRemote(c); err != nil {
718719
return err
719720
}
720721

721722
ref, err := r.fetchAndUpdateReferences(ctx, &FetchOptions{
722-
RefSpecs: r.cloneRefSpec(o, c),
723+
RefSpecs: c.Fetch,
723724
Depth: o.Depth,
724725
Auth: o.Auth,
725726
Progress: o.Progress,
@@ -789,18 +790,18 @@ const (
789790
refspecSingleBranchHEAD = "+HEAD:refs/remotes/%s/HEAD"
790791
)
791792

792-
func (r *Repository) cloneRefSpec(o *CloneOptions, c *config.RemoteConfig) []config.RefSpec {
793+
func (r *Repository) cloneRefSpec(o *CloneOptions) []config.RefSpec {
793794
var rs string
794795

795796
switch {
796797
case o.ReferenceName.IsTag():
797798
rs = fmt.Sprintf(refspecTag, o.ReferenceName.Short())
798799
case o.SingleBranch && o.ReferenceName == plumbing.HEAD:
799-
rs = fmt.Sprintf(refspecSingleBranchHEAD, c.Name)
800+
rs = fmt.Sprintf(refspecSingleBranchHEAD, o.RemoteName)
800801
case o.SingleBranch:
801-
rs = fmt.Sprintf(refspecSingleBranch, o.ReferenceName.Short(), c.Name)
802+
rs = fmt.Sprintf(refspecSingleBranch, o.ReferenceName.Short(), o.RemoteName)
802803
default:
803-
return c.Fetch
804+
return []config.RefSpec{config.RefSpec(fmt.Sprintf(config.DefaultFetchRefSpec, o.RemoteName))}
804805
}
805806

806807
return []config.RefSpec{config.RefSpec(rs)}
@@ -821,9 +822,11 @@ func (r *Repository) updateRemoteConfigIfNeeded(o *CloneOptions, c *config.Remot
821822
return nil
822823
}
823824

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)
827830

828831
cfg, err := r.Storer.Config()
829832
if err != nil {

0 commit comments

Comments
 (0)