aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--remote.go31
-rw-r--r--remote_test.go19
2 files changed, 44 insertions, 6 deletions
diff --git a/remote.go b/remote.go
index d94b2ad..7814255 100644
--- a/remote.go
+++ b/remote.go
@@ -190,8 +190,8 @@ func (r *Remote) updateObjectStorage(reader io.Reader) error {
}
func (r *Remote) updateLocalReferenceStorage(specs []config.RefSpec, refs []*core.Reference) error {
- for _, ref := range refs {
- for _, spec := range specs {
+ for _, spec := range specs {
+ for _, ref := range refs {
if !spec.Match(ref.Name()) {
continue
}
@@ -208,7 +208,32 @@ func (r *Remote) updateLocalReferenceStorage(specs []config.RefSpec, refs []*cor
}
}
- return nil
+ return r.buildFetchedTags()
+}
+
+func (r *Remote) buildFetchedTags() error {
+ iter, err := r.Refs()
+ if err != nil {
+ return err
+ }
+
+ os := r.s.ObjectStorage()
+ return iter.ForEach(func(ref *core.Reference) error {
+ if !ref.IsTag() {
+ return nil
+ }
+
+ _, err := os.Get(core.CommitObject, ref.Hash())
+ if err == core.ErrObjectNotFound {
+ return nil
+ }
+
+ if err != nil {
+ return err
+ }
+
+ return r.s.ReferenceStorage().Set(ref)
+ })
}
// Head returns the Reference of the HEAD
diff --git a/remote_test.go b/remote_test.go
index cb5cca5..7aaaac7 100644
--- a/remote_test.go
+++ b/remote_test.go
@@ -13,6 +13,8 @@ import (
. "gopkg.in/check.v1"
)
+const FixRefSpec = config.RefSpec("+refs/heads/*:refs/remotes/origin/*")
+
type RemoteSuite struct {
BaseSuite
}
@@ -74,11 +76,22 @@ func (s *RemoteSuite) TestFetch(c *C) {
c.Assert(r.Connect(), IsNil)
err := r.Fetch(&FetchOptions{
- RefSpecs: []config.RefSpec{config.DefaultRefSpec},
+ RefSpecs: []config.RefSpec{FixRefSpec},
})
c.Assert(err, IsNil)
c.Assert(sto.ObjectStorage().(*memory.ObjectStorage).Objects, HasLen, 31)
+
+ expectedRefs := []*core.Reference{
+ core.NewReferenceFromStrings("refs/remotes/origin/master", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5"),
+ core.NewReferenceFromStrings("refs/remotes/origin/branch", "e8d3ffab552895c19b9fcf7aa264d277cde33881"),
+ core.NewReferenceFromStrings("refs/tags/v1.0.0", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5"),
+ }
+
+ for _, exp := range expectedRefs {
+ r, _ := sto.ReferenceStorage().Get(exp.Name())
+ c.Assert(exp.String(), Equals, r.String())
+ }
}
func (s *RemoteSuite) TestFetchObjectStorageWriter(c *C) {
@@ -97,7 +110,7 @@ func (s *RemoteSuite) TestFetchObjectStorageWriter(c *C) {
c.Assert(r.Connect(), IsNil)
err = r.Fetch(&FetchOptions{
- RefSpecs: []config.RefSpec{config.DefaultRefSpec},
+ RefSpecs: []config.RefSpec{FixRefSpec},
})
c.Assert(err, IsNil)
@@ -121,7 +134,7 @@ func (s *RemoteSuite) TestFetchNoErrAlreadyUpToDate(c *C) {
c.Assert(r.Connect(), IsNil)
o := &FetchOptions{
- RefSpecs: []config.RefSpec{config.DefaultRefSpec},
+ RefSpecs: []config.RefSpec{FixRefSpec},
}
err := r.Fetch(o)