aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-09-04 13:53:55 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-09-04 13:53:55 +0200
commit38b9d5711a0d8156a5b5b1e5dd9972558b1389a7 (patch)
tree6f06300b57c4d6d11b1c5d3b2b01d6f6c8737634
parentc20028f6a4d0038d59898392aafe13baa9e84040 (diff)
downloadgo-git-38b9d5711a0d8156a5b5b1e5dd9972558b1389a7.tar.gz
Remote.Fetch Tags logic improvement and fix NoTags
-rw-r--r--remote.go22
-rw-r--r--remote_test.go2
2 files changed, 17 insertions, 7 deletions
diff --git a/remote.go b/remote.go
index 1c9d1cd..3e24763 100644
--- a/remote.go
+++ b/remote.go
@@ -279,7 +279,7 @@ func (r *Remote) fetch(ctx context.Context, o *FetchOptions) (storer.ReferenceSt
}
}
- updated, err := r.updateLocalReferenceStorage(o.RefSpecs, refs, remoteRefs)
+ updated, err := r.updateLocalReferenceStorage(o.RefSpecs, refs, remoteRefs, o.Tags)
if err != nil {
return nil, err
}
@@ -481,10 +481,17 @@ func getHaves(localRefs storer.ReferenceStorer) ([]plumbing.Hash, error) {
return result, nil
}
-func calculateRefs(spec []config.RefSpec,
+const refspecTag = "+refs/tags/*:refs/tags/*"
+
+func calculateRefs(
+ spec []config.RefSpec,
remoteRefs storer.ReferenceStorer,
- tags TagFetchMode,
+ tagMode TagMode,
) (memory.ReferenceStorage, error) {
+ if tagMode == AllTags {
+ spec = append(spec, refspecTag)
+ }
+
iter, err := remoteRefs.IterReferences()
if err != nil {
return nil, err
@@ -493,9 +500,7 @@ func calculateRefs(spec []config.RefSpec,
refs := make(memory.ReferenceStorage, 0)
return refs, iter.ForEach(func(ref *plumbing.Reference) error {
if !config.MatchAny(spec, ref.Name()) {
- if !ref.Name().IsTag() || tags != AllTags {
- return nil
- }
+ return nil
}
if ref.Type() == plumbing.SymbolicReference {
@@ -645,6 +650,7 @@ func buildSidebandIfSupported(l *capability.List, reader io.Reader, p sideband.P
func (r *Remote) updateLocalReferenceStorage(
specs []config.RefSpec,
fetchedRefs, remoteRefs memory.ReferenceStorage,
+ tagMode TagMode,
) (updated bool, err error) {
isWildcard := true
for _, spec := range specs {
@@ -674,6 +680,10 @@ func (r *Remote) updateLocalReferenceStorage(
}
}
+ if tagMode == NoTags {
+ return updated, nil
+ }
+
tags := fetchedRefs
if isWildcard {
tags = remoteRefs
diff --git a/remote_test.go b/remote_test.go
index 51180ce..10f6708 100644
--- a/remote_test.go
+++ b/remote_test.go
@@ -143,7 +143,7 @@ func (s *RemoteSuite) TestFetchWithNoTags(c *C) {
s.testFetch(c, r, &FetchOptions{
Tags: NoTags,
RefSpecs: []config.RefSpec{
- config.RefSpec("+refs/heads/master:refs/remotes/origin/master"),
+ config.RefSpec("+refs/heads/*:refs/remotes/origin/*"),
},
}, []*plumbing.Reference{
plumbing.NewReferenceFromStrings("refs/remotes/origin/master", "f7b877701fbf855b44c0a9e86f3fdce2c298b07f"),