Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Remote.Fetch: error on missing remote reference #870

Merged
merged 1 commit into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())},
Expand Down