diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-10-26 23:45:37 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-10-26 23:45:37 +0200 |
commit | 0c3bc0c8b3eabe16e927475f26044ca9aaa50351 (patch) | |
tree | 219d36a5cd5b13af6c0231176ddca9b728a308b2 | |
parent | c66f495b35b12c6827507b9933b39a10fa94379b (diff) | |
download | go-git-0c3bc0c8b3eabe16e927475f26044ca9aaa50351.tar.gz |
remote, fix copy tag reference on fetch
-rw-r--r-- | remote.go | 31 | ||||
-rw-r--r-- | remote_test.go | 19 |
2 files changed, 44 insertions, 6 deletions
@@ -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) |