aboutsummaryrefslogtreecommitdiffstats
path: root/repository.go
diff options
context:
space:
mode:
Diffstat (limited to 'repository.go')
-rw-r--r--repository.go29
1 files changed, 14 insertions, 15 deletions
diff --git a/repository.go b/repository.go
index e2a18c4..72beefd 100644
--- a/repository.go
+++ b/repository.go
@@ -448,20 +448,24 @@ func (r *Repository) clone(ctx context.Context, o *CloneOptions) error {
return r.updateRemoteConfigIfNeeded(o, c, head)
}
-func (r *Repository) cloneRefSpec(o *CloneOptions,
- c *config.RemoteConfig) []config.RefSpec {
-
- if !o.SingleBranch {
- return c.Fetch
- }
+const (
+ refspecTagWithDepth = "+refs/tags/%s:refs/tags/%[1]s"
+ refspecSingleBranch = "+refs/heads/%s:refs/remotes/%s/%[1]s"
+ refspecSingleBranchHEAD = "+HEAD:refs/remotes/%s/HEAD"
+)
+func (r *Repository) cloneRefSpec(o *CloneOptions, c *config.RemoteConfig) []config.RefSpec {
var rs string
- if o.ReferenceName == plumbing.HEAD {
+ switch {
+ case o.ReferenceName.IsTag() && o.Depth > 0:
+ rs = fmt.Sprintf(refspecTagWithDepth, o.ReferenceName.Short())
+ case o.SingleBranch && o.ReferenceName == plumbing.HEAD:
rs = fmt.Sprintf(refspecSingleBranchHEAD, c.Name)
- } else {
- rs = fmt.Sprintf(refspecSingleBranch,
- o.ReferenceName.Short(), c.Name)
+ case o.SingleBranch:
+ rs = fmt.Sprintf(refspecSingleBranch, o.ReferenceName.Short(), c.Name)
+ default:
+ return c.Fetch
}
return []config.RefSpec{config.RefSpec(rs)}
@@ -477,11 +481,6 @@ func (r *Repository) setIsBare(isBare bool) error {
return r.Storer.SetConfig(cfg)
}
-const (
- refspecSingleBranch = "+refs/heads/%s:refs/remotes/%s/%[1]s"
- refspecSingleBranchHEAD = "+HEAD:refs/remotes/%s/HEAD"
-)
-
func (r *Repository) updateRemoteConfigIfNeeded(o *CloneOptions, c *config.RemoteConfig, head *plumbing.Reference) error {
if !o.SingleBranch {
return nil