aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-10-27 02:42:36 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-10-27 02:42:36 +0200
commit0c6c4047155692caff733d0cd239b80508b7bd04 (patch)
tree522bc02e7c5e4f4f3968a7b38c74bc9773097d1f
parent0c3bc0c8b3eabe16e927475f26044ca9aaa50351 (diff)
downloadgo-git-0c6c4047155692caff733d0cd239b80508b7bd04.tar.gz
remote, fix fetch tags
-rw-r--r--common_test.go1
-rw-r--r--config/refspec.go7
-rw-r--r--options.go4
-rw-r--r--remote.go14
-rw-r--r--repository_test.go19
-rw-r--r--tag.go21
6 files changed, 44 insertions, 22 deletions
diff --git a/common_test.go b/common_test.go
index 7a3310f..854db3a 100644
--- a/common_test.go
+++ b/common_test.go
@@ -97,6 +97,7 @@ func (p *MockGitUploadPackService) Info() (*common.GitUploadPackInfo, error) {
ref := core.ReferenceName("refs/heads/master")
branch := core.ReferenceName("refs/heads/branch")
tag := core.ReferenceName("refs/tags/v1.0.0")
+
return &common.GitUploadPackInfo{
Capabilities: c,
Refs: map[core.ReferenceName]*core.Reference{
diff --git a/config/refspec.go b/config/refspec.go
index dae13be..9b5560d 100644
--- a/config/refspec.go
+++ b/config/refspec.go
@@ -59,14 +59,15 @@ func (s RefSpec) Src() string {
// Match match the given core.ReferenceName against the source
func (s RefSpec) Match(n core.ReferenceName) bool {
- if !s.isGlob() {
+ if !s.IsWildcard() {
return s.matchExact(n)
}
return s.matchGlob(n)
}
-func (s RefSpec) isGlob() bool {
+// IsWildcard returns true if the RefSpec contains a wildcard
+func (s RefSpec) IsWildcard() bool {
return strings.Index(string(s), refSpecWildcard) != -1
}
@@ -97,7 +98,7 @@ func (s RefSpec) Dst(n core.ReferenceName) core.ReferenceName {
dst := spec[start:len(spec)]
src := s.Src()
- if !s.isGlob() {
+ if !s.IsWildcard() {
return core.ReferenceName(dst)
}
diff --git a/options.go b/options.go
index 34f4dcd..4d289e9 100644
--- a/options.go
+++ b/options.go
@@ -79,7 +79,9 @@ func (o *PullOptions) Validate() error {
// FetchOptions describe how a fetch should be perform
type FetchOptions struct {
RefSpecs []config.RefSpec
- Depth int
+ // Depth limit fetching to the specified number of commits from the tip of
+ // each remote branch history.
+ Depth int
}
// Validate validate the fields and set the default values
diff --git a/remote.go b/remote.go
index 7814255..e7028e8 100644
--- a/remote.go
+++ b/remote.go
@@ -120,13 +120,23 @@ func (r *Remote) getWantedReferences(spec []config.RefSpec) ([]*core.Reference,
return refs, err
}
+ wantTags := true
+ for _, s := range spec {
+ if !s.IsWildcard() {
+ wantTags = false
+ break
+ }
+ }
+
return refs, iter.ForEach(func(ref *core.Reference) error {
if ref.Type() != core.HashReference {
return nil
}
if !config.MatchAny(spec, ref.Name()) {
- return nil
+ if !ref.IsTag() || !wantTags {
+ return nil
+ }
}
_, err := r.s.ObjectStorage().Get(core.CommitObject, ref.Hash())
@@ -223,7 +233,7 @@ func (r *Remote) buildFetchedTags() error {
return nil
}
- _, err := os.Get(core.CommitObject, ref.Hash())
+ _, err := os.Get(core.AnyObject, ref.Hash())
if err == core.ErrObjectNotFound {
return nil
}
diff --git a/repository_test.go b/repository_test.go
index 07fa763..b67e31d 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -314,24 +314,27 @@ func (s *RepositorySuite) TestTag(c *C) {
func (s *RepositorySuite) TestTags(c *C) {
r := NewMemoryRepository()
- err := r.Clone(&CloneOptions{URL: "https://github.com/spinnaker/spinnaker.git"})
+ err := r.Clone(&CloneOptions{URL: "https://github.com/git-fixtures/tags.git"})
c.Assert(err, IsNil)
count := 0
tags, err := r.Tags()
c.Assert(err, IsNil)
- for {
- tag, err := tags.Next()
- if err != nil {
- break
- }
+ tags.ForEach(func(tag *Tag) error {
count++
c.Assert(tag.Hash.IsZero(), Equals, false)
c.Assert(tag.Type(), Equals, core.TagObject)
- }
- c.Assert(count, Equals, 11)
+ return nil
+ })
+
+ refs, _ := r.Refs()
+ refs.ForEach(func(ref *core.Reference) error {
+ return nil
+ })
+
+ c.Assert(count, Equals, 4)
}
func (s *RepositorySuite) TestCommitIterClosePanic(c *C) {
diff --git a/tag.go b/tag.go
index 4d039ab..0a8014b 100644
--- a/tag.go
+++ b/tag.go
@@ -28,13 +28,6 @@ type Tag struct {
r *Repository
}
-// Type returns the type of object. It always returns core.TreeObject.
-/*
-func (t *Tag) Type() core.ObjectType {
- return core.TagObject
-}
-*/
-
// ID returns the object ID of the tag, not the object that the tag references.
// The returned value will always match the current value of Tag.Hash.
//
@@ -180,10 +173,11 @@ func (t *Tag) Object() (Object, error) {
// string.
func (t *Tag) String() string {
obj, _ := t.Object()
+
return fmt.Sprintf(
"%s %s\nTagger: %s\nDate: %s\n\n%s\n%s",
core.TagObject, t.Name, t.Tagger.String(), t.Tagger.When.Format(DateFormat),
- t.Message, obj,
+ t.Message, objectAsString(obj),
)
}
@@ -226,3 +220,14 @@ func (iter *TagIter) ForEach(cb func(*Tag) error) error {
return cb(tag)
})
}
+
+func objectAsString(obj Object) string {
+ switch o := obj.(type) {
+ case *Commit:
+ return o.String()
+ case *Tag:
+ return o.String()
+ }
+
+ return ""
+}