Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 7cdc443

Browse files
committed
Repository.Clone added Tags option, and set by default AllTags as git does
1 parent 38b9d57 commit 7cdc443

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

options.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ type CloneOptions struct {
5050
// stored, if nil nothing is stored and the capability (if supported)
5151
// no-progress, is sent to the server to avoid send this information.
5252
Progress sideband.Progress
53+
// Tags describe how the tags will be fetched from the remote repository,
54+
// by default is AllTags.
55+
Tags TagMode
5356
}
5457

5558
// Validate validates the fields and sets the default values.
@@ -66,6 +69,10 @@ func (o *CloneOptions) Validate() error {
6669
o.ReferenceName = plumbing.HEAD
6770
}
6871

72+
if o.Tags == InvalidTagMode {
73+
o.Tags = AllTags
74+
}
75+
6976
return nil
7077
}
7178

@@ -103,18 +110,19 @@ func (o *PullOptions) Validate() error {
103110
return nil
104111
}
105112

106-
type TagFetchMode int
113+
type TagMode int
107114

108-
var (
115+
const (
116+
InvalidTagMode TagMode = iota
109117
// TagFollowing any tag that points into the histories being fetched is also
110118
// fetched. TagFollowing requires a server with `include-tag` capability
111119
// in order to fetch the annotated tags objects.
112-
TagFollowing TagFetchMode = 0
120+
TagFollowing
113121
// AllTags fetch all tags from the remote (i.e., fetch remote tags
114122
// refs/tags/* into local tags with the same name)
115-
AllTags TagFetchMode = 1
123+
AllTags
116124
//NoTags fetch no tags from the remote at all
117-
NoTags TagFetchMode = 2
125+
NoTags
118126
)
119127

120128
// FetchOptions describes how a fetch should be performed
@@ -133,7 +141,7 @@ type FetchOptions struct {
133141
Progress sideband.Progress
134142
// Tags describe how the tags will be fetched from the remote repository,
135143
// by default is TagFollowing.
136-
Tags TagFetchMode
144+
Tags TagMode
137145
}
138146

139147
// Validate validates the fields and sets the default values.
@@ -142,6 +150,10 @@ func (o *FetchOptions) Validate() error {
142150
o.RemoteName = DefaultRemoteName
143151
}
144152

153+
if o.Tags == InvalidTagMode {
154+
o.Tags = TagFollowing
155+
}
156+
145157
for _, r := range o.RefSpecs {
146158
if err := r.Validate(); err != nil {
147159
return err

repository.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ func (r *Repository) clone(ctx context.Context, o *CloneOptions) error {
440440
Depth: o.Depth,
441441
Auth: o.Auth,
442442
Progress: o.Progress,
443+
Tags: o.Tags,
443444
}, o.ReferenceName)
444445
if err != nil {
445446
return err

repository_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,27 @@ func (s *RepositorySuite) TestCloneContext(c *C) {
177177
c.Assert(err, NotNil)
178178
}
179179

180+
func (s *RepositorySuite) TestCloneWithTags(c *C) {
181+
url := s.GetLocalRepositoryURL(
182+
fixtures.ByURL("https://github.com/git-fixtures/tags.git").One(),
183+
)
184+
185+
r, err := Clone(memory.NewStorage(), nil, &CloneOptions{URL: url, Tags: NoTags})
186+
c.Assert(err, IsNil)
187+
188+
remotes, err := r.Remotes()
189+
c.Assert(err, IsNil)
190+
c.Assert(remotes, HasLen, 1)
191+
192+
i, err := r.References()
193+
c.Assert(err, IsNil)
194+
195+
var count int
196+
i.ForEach(func(r *plumbing.Reference) error { count++; return nil })
197+
198+
c.Assert(count, Equals, 3)
199+
}
200+
180201
func (s *RepositorySuite) TestCreateRemoteAndRemote(c *C) {
181202
r, _ := Init(memory.NewStorage(), nil)
182203
remote, err := r.CreateRemote(&config.RemoteConfig{

0 commit comments

Comments
 (0)