diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-09-04 13:54:02 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-09-04 13:54:02 +0200 |
commit | 7cdc44306dd1b3bba4a219bf3c40c5097a505a8e (patch) | |
tree | 2a6300e33f07f54cb1f7756100386430215a11d7 | |
parent | 38b9d5711a0d8156a5b5b1e5dd9972558b1389a7 (diff) | |
download | go-git-7cdc44306dd1b3bba4a219bf3c40c5097a505a8e.tar.gz |
Repository.Clone added Tags option, and set by default AllTags as git does
-rw-r--r-- | options.go | 24 | ||||
-rw-r--r-- | repository.go | 1 | ||||
-rw-r--r-- | repository_test.go | 21 |
3 files changed, 40 insertions, 6 deletions
@@ -50,6 +50,9 @@ type CloneOptions struct { // stored, if nil nothing is stored and the capability (if supported) // no-progress, is sent to the server to avoid send this information. Progress sideband.Progress + // Tags describe how the tags will be fetched from the remote repository, + // by default is AllTags. + Tags TagMode } // Validate validates the fields and sets the default values. @@ -66,6 +69,10 @@ func (o *CloneOptions) Validate() error { o.ReferenceName = plumbing.HEAD } + if o.Tags == InvalidTagMode { + o.Tags = AllTags + } + return nil } @@ -103,18 +110,19 @@ func (o *PullOptions) Validate() error { return nil } -type TagFetchMode int +type TagMode int -var ( +const ( + InvalidTagMode TagMode = iota // TagFollowing any tag that points into the histories being fetched is also // fetched. TagFollowing requires a server with `include-tag` capability // in order to fetch the annotated tags objects. - TagFollowing TagFetchMode = 0 + TagFollowing // AllTags fetch all tags from the remote (i.e., fetch remote tags // refs/tags/* into local tags with the same name) - AllTags TagFetchMode = 1 + AllTags //NoTags fetch no tags from the remote at all - NoTags TagFetchMode = 2 + NoTags ) // FetchOptions describes how a fetch should be performed @@ -133,7 +141,7 @@ type FetchOptions struct { Progress sideband.Progress // Tags describe how the tags will be fetched from the remote repository, // by default is TagFollowing. - Tags TagFetchMode + Tags TagMode } // Validate validates the fields and sets the default values. @@ -142,6 +150,10 @@ func (o *FetchOptions) Validate() error { o.RemoteName = DefaultRemoteName } + if o.Tags == InvalidTagMode { + o.Tags = TagFollowing + } + for _, r := range o.RefSpecs { if err := r.Validate(); err != nil { return err diff --git a/repository.go b/repository.go index fbc7871..b86054f 100644 --- a/repository.go +++ b/repository.go @@ -440,6 +440,7 @@ func (r *Repository) clone(ctx context.Context, o *CloneOptions) error { Depth: o.Depth, Auth: o.Auth, Progress: o.Progress, + Tags: o.Tags, }, o.ReferenceName) if err != nil { return err diff --git a/repository_test.go b/repository_test.go index 6184949..4480484 100644 --- a/repository_test.go +++ b/repository_test.go @@ -177,6 +177,27 @@ func (s *RepositorySuite) TestCloneContext(c *C) { c.Assert(err, NotNil) } +func (s *RepositorySuite) TestCloneWithTags(c *C) { + url := s.GetLocalRepositoryURL( + fixtures.ByURL("https://github.com/git-fixtures/tags.git").One(), + ) + + r, err := Clone(memory.NewStorage(), nil, &CloneOptions{URL: url, Tags: NoTags}) + c.Assert(err, IsNil) + + remotes, err := r.Remotes() + c.Assert(err, IsNil) + c.Assert(remotes, HasLen, 1) + + i, err := r.References() + c.Assert(err, IsNil) + + var count int + i.ForEach(func(r *plumbing.Reference) error { count++; return nil }) + + c.Assert(count, Equals, 3) +} + func (s *RepositorySuite) TestCreateRemoteAndRemote(c *C) { r, _ := Init(memory.NewStorage(), nil) remote, err := r.CreateRemote(&config.RemoteConfig{ |