diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-10-04 16:56:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-04 16:56:36 +0200 |
commit | a99c1291da1bf5c4ae8fada815231922f106bb70 (patch) | |
tree | 30af59374899c3537e1d257a65f9ab8f5733c73d /remote.go | |
parent | 30a99a264355ff1125c5464ad72965e927b1baea (diff) | |
parent | b8eac90c420e14ebbabbb15523d024a4064e12ef (diff) | |
download | go-git-a99c1291da1bf5c4ae8fada815231922f106bb70.tar.gz |
Merge pull request #609 from darkowlzz/ls-remote
remote: add support for ls-remote
Diffstat (limited to 'remote.go')
-rw-r--r-- | remote.go | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -759,6 +759,39 @@ func (r *Remote) buildFetchedTags(refs memory.ReferenceStorage) (updated bool, e return } +// List the references on the remote repository. +func (r *Remote) List(o *ListOptions) ([]*plumbing.Reference, error) { + s, err := newUploadPackSession(r.c.URLs[0], o.Auth) + if err != nil { + return nil, err + } + + defer ioutil.CheckClose(s, &err) + + ar, err := s.AdvertisedReferences() + if err != nil { + return nil, err + } + + allRefs, err := ar.AllReferences() + if err != nil { + return nil, err + } + + refs, err := allRefs.IterReferences() + if err != nil { + return nil, err + } + + var resultRefs []*plumbing.Reference + refs.ForEach(func(ref *plumbing.Reference) error { + resultRefs = append(resultRefs, ref) + return nil + }) + + return resultRefs, nil +} + func objectsToPush(commands []*packp.Command) ([]plumbing.Hash, error) { var objects []plumbing.Hash for _, cmd := range commands { |