diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2018-06-26 14:04:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-26 14:04:45 +0200 |
commit | 662e2c226e9b8352a90cd1951233fab30a4e5042 (patch) | |
tree | 27c4aaadba52b8c6f4ff8176ac98952a3bcb007b | |
parent | b11eaabdfd82deb68537fd44176d58084a6f367d (diff) | |
parent | b53ba8dcffd24e25815feff78e8246597e949f21 (diff) | |
download | go-git-662e2c226e9b8352a90cd1951233fab30a4e5042.tar.gz |
Merge pull request #870 from mcuadros/fetch-error
Remote.Fetch: error on missing remote reference
-rw-r--r-- | remote.go | 40 | ||||
-rw-r--r-- | remote_test.go | 14 |
2 files changed, 49 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) { diff --git a/remote_test.go b/remote_test.go index 82ec1fc..dd386b0 100644 --- a/remote_test.go +++ b/remote_test.go @@ -100,6 +100,20 @@ func (s *RemoteSuite) TestFetch(c *C) { }) } +func (s *RemoteSuite) TestFetchNonExistantReference(c *C) { + r := newRemote(memory.NewStorage(), &config.RemoteConfig{ + URLs: []string{s.GetLocalRepositoryURL(fixtures.ByTag("tags").One())}, + }) + + err := r.Fetch(&FetchOptions{ + RefSpecs: []config.RefSpec{ + config.RefSpec("+refs/heads/foo:refs/remotes/origin/foo"), + }, + }) + + c.Assert(err, ErrorMatches, "couldn't find remote ref.*") +} + func (s *RemoteSuite) TestFetchContext(c *C) { r := newRemote(memory.NewStorage(), &config.RemoteConfig{ URLs: []string{s.GetLocalRepositoryURL(fixtures.ByTag("tags").One())}, |