diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2018-06-21 12:40:21 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2018-06-21 12:40:21 +0200 |
commit | b53ba8dcffd24e25815feff78e8246597e949f21 (patch) | |
tree | 377ed463706d8e88732e9bd877af97afbf0f05b0 /remote.go | |
parent | 0710c6cb710a0cdab04ab7f61cc62e23cfcacbee (diff) | |
download | go-git-b53ba8dcffd24e25815feff78e8246597e949f21.tar.gz |
Remote.Fetch: error on missing remote reference
Signed-off-by: Máximo Cuadros <mcuadros@gmail.com>
Diffstat (limited to 'remote.go')
-rw-r--r-- | remote.go | 40 |
1 files changed, 35 insertions, 5 deletions
@@ -630,14 +630,29 @@ func calculateRefs( spec = append(spec, refspecTag) } + refs := make(memory.ReferenceStorage) + for _, s := range spec { + if err := doCalculateRefs(s, remoteRefs, refs); err != nil { + return nil, err + } + } + + return refs, nil +} + +func doCalculateRefs( + s config.RefSpec, + remoteRefs storer.ReferenceStorer, + refs memory.ReferenceStorage, +) error { iter, err := remoteRefs.IterReferences() if err != nil { - return nil, err + return err } - refs := make(memory.ReferenceStorage) - return refs, iter.ForEach(func(ref *plumbing.Reference) error { - if !config.MatchAny(spec, ref.Name()) { + var matched bool + err = iter.ForEach(func(ref *plumbing.Reference) error { + if !s.Match(ref.Name()) { return nil } @@ -654,8 +669,23 @@ func calculateRefs( return nil } - return refs.SetReference(ref) + matched = true + if err := refs.SetReference(ref); err != nil { + return err + } + + if !s.IsWildcard() { + return storer.ErrStop + } + + return nil }) + + if !matched && !s.IsWildcard() { + return fmt.Errorf("couldn't find remote ref %q", s.Src()) + } + + return err } func getWants(localStorer storage.Storer, refs memory.ReferenceStorage) ([]plumbing.Hash, error) { |