Skip to content

Commit

Permalink
Fix RefSpec for a single tag
Browse files Browse the repository at this point in the history
Fixes src-d#960
  • Loading branch information
fkorotkov committed Nov 1, 2018
1 parent 959dc01 commit 685e6e2
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,16 +710,17 @@ func (r *Repository) clone(ctx context.Context, o *CloneOptions) error {
}

c := &config.RemoteConfig{
Name: o.RemoteName,
URLs: []string{o.URL},
Name: o.RemoteName,
URLs: []string{o.URL},
Fetch: r.cloneRefSpec(o),
}

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

ref, err := r.fetchAndUpdateReferences(ctx, &FetchOptions{
RefSpecs: r.cloneRefSpec(o, c),
RefSpecs: c.Fetch,
Depth: o.Depth,
Auth: o.Auth,
Progress: o.Progress,
Expand Down Expand Up @@ -789,18 +790,18 @@ const (
refspecSingleBranchHEAD = "+HEAD:refs/remotes/%s/HEAD"
)

func (r *Repository) cloneRefSpec(o *CloneOptions, c *config.RemoteConfig) []config.RefSpec {
func (r *Repository) cloneRefSpec(o *CloneOptions) []config.RefSpec {
var rs string

switch {
case o.ReferenceName.IsTag():
rs = fmt.Sprintf(refspecTag, o.ReferenceName.Short())
case o.SingleBranch && o.ReferenceName == plumbing.HEAD:
rs = fmt.Sprintf(refspecSingleBranchHEAD, c.Name)
rs = fmt.Sprintf(refspecSingleBranchHEAD, o.RemoteName)
case o.SingleBranch:
rs = fmt.Sprintf(refspecSingleBranch, o.ReferenceName.Short(), c.Name)
rs = fmt.Sprintf(refspecSingleBranch, o.ReferenceName.Short(), o.RemoteName)
default:
return c.Fetch
return []config.RefSpec{config.RefSpec(fmt.Sprintf(config.DefaultFetchRefSpec, o.RemoteName))}
}

return []config.RefSpec{config.RefSpec(rs)}
Expand All @@ -821,9 +822,7 @@ func (r *Repository) updateRemoteConfigIfNeeded(o *CloneOptions, c *config.Remot
return nil
}

c.Fetch = []config.RefSpec{config.RefSpec(fmt.Sprintf(
refspecSingleBranch, head.Name().Short(), c.Name,
))}
c.Fetch = r.cloneRefSpec(o)

cfg, err := r.Storer.Config()
if err != nil {
Expand Down

0 comments on commit 685e6e2

Please sign in to comment.