aboutsummaryrefslogtreecommitdiffstats
path: root/remote.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-08-22 00:18:02 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-08-22 00:18:02 +0200
commitf42d82364c5d159f65a48e720433ad2bc97f0b7f (patch)
tree82623f4163625786f4e8e41028dcd1c7abaf209f /remote.go
parenta045606fc9c5cbf30b409384cbdad4804f01c61d (diff)
downloadgo-git-f42d82364c5d159f65a48e720433ad2bc97f0b7f.tar.gz
Remote.Fetch multiple RefSpec support
Diffstat (limited to 'remote.go')
-rw-r--r--remote.go61
1 files changed, 39 insertions, 22 deletions
diff --git a/remote.go b/remote.go
index b023497..6c020ca 100644
--- a/remote.go
+++ b/remote.go
@@ -1,6 +1,7 @@
package git
import (
+ "fmt"
"io"
"gopkg.in/src-d/go-git.v4/clients"
@@ -24,6 +25,11 @@ func newRemote(s Storage, c *config.RemoteConfig) *Remote {
return &Remote{s: s, c: c}
}
+// Config return the config
+func (r *Remote) Config() *config.RemoteConfig {
+ return r.c
+}
+
// Connect with the endpoint
func (r *Remote) Connect() error {
if err := r.connectUploadPackService(); err != nil {
@@ -72,7 +78,11 @@ func (r *Remote) Fetch(o *RemoteFetchOptions) (err error) {
return err
}
- refs, err := r.getWantedReferences(o.RefSpec)
+ if len(o.RefSpecs) == 0 {
+ o.RefSpecs = r.c.Fetch
+ }
+
+ refs, err := r.getWantedReferences(o.RefSpecs)
if err != nil {
return err
}
@@ -88,14 +98,14 @@ func (r *Remote) Fetch(o *RemoteFetchOptions) (err error) {
}
defer checkClose(reader, &err)
- if err := r.updateObjectStorage(r.s.ObjectStorage(), reader); err != nil {
+ if err := r.updateObjectStorage(reader); err != nil {
return err
}
- return r.updateLocalReferenceStorage(r.s.ReferenceStorage(), o.RefSpec, refs)
+ return r.updateLocalReferenceStorage(o.RefSpecs, refs)
}
-func (r *Remote) getWantedReferences(spec config.RefSpec) ([]*core.Reference, error) {
+func (r *Remote) getWantedReferences(spec []config.RefSpec) ([]*core.Reference, error) {
var refs []*core.Reference
return refs, r.Refs().ForEach(func(r *core.Reference) error {
@@ -103,7 +113,7 @@ func (r *Remote) getWantedReferences(spec config.RefSpec) ([]*core.Reference, er
return nil
}
- if spec.Match(r.Name()) {
+ if config.MatchAny(spec, r.Name()) {
refs = append(refs, r)
}
@@ -138,29 +148,29 @@ func (r *Remote) buildRequest(
return req, err
}
-func (r *Remote) updateObjectStorage(s core.ObjectStorage, reader io.Reader) error {
+func (r *Remote) updateObjectStorage(reader io.Reader) error {
stream := packfile.NewStream(reader)
d := packfile.NewDecoder(stream)
- return d.Decode(s)
+ return d.Decode(r.s.ObjectStorage())
}
-func (r *Remote) updateLocalReferenceStorage(
- local core.ReferenceStorage, spec config.RefSpec, refs []*core.Reference,
-) error {
+func (r *Remote) updateLocalReferenceStorage(specs []config.RefSpec, refs []*core.Reference) error {
for _, ref := range refs {
- if !spec.Match(ref.Name()) {
- continue
- }
-
- if ref.Type() != core.HashReference {
- continue
- }
-
- name := spec.Dst(ref.Name())
- n := core.NewHashReference(name, ref.Hash())
- if err := local.Set(n); err != nil {
- return err
+ for _, spec := range specs {
+ if !spec.Match(ref.Name()) {
+ continue
+ }
+
+ if ref.Type() != core.HashReference {
+ continue
+ }
+
+ name := spec.Dst(ref.Name())
+ n := core.NewHashReference(name, ref.Hash())
+ if err := r.s.ReferenceStorage().Set(n); err != nil {
+ return err
+ }
}
}
@@ -192,3 +202,10 @@ func (r *Remote) Disconnect() error {
r.upInfo = nil
return r.upSrv.Disconnect()
}
+
+func (r *Remote) String() string {
+ fetch := r.c.URL
+ push := r.c.URL
+
+ return fmt.Sprintf("%s\t%s (fetch)\n%[1]s\t%s (push)", r.c.Name, fetch, push)
+}