From e69dab7fd7800c0c34c4caf2157f5d9c6638d855 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Thu, 12 Jan 2017 14:48:31 +0100 Subject: remote: fix empty-git-upload-pack error in fetch, when the reference points to a non-commit object (#209) --- remote.go | 7 ++++--- remote_test.go | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/remote.go b/remote.go index 1894fdc..c3fa042 100644 --- a/remote.go +++ b/remote.go @@ -355,7 +355,8 @@ func getWants(spec []config.RefSpec, localStorer Storer, remoteRefs storer.Refer } hash := ref.Hash() - exists, err := commitExists(localStorer, hash) + + exists, err := objectExists(localStorer, hash) if err != nil { return err } @@ -378,8 +379,8 @@ func getWants(spec []config.RefSpec, localStorer Storer, remoteRefs storer.Refer return result, nil } -func commitExists(s storer.EncodedObjectStorer, h plumbing.Hash) (bool, error) { - _, err := s.EncodedObject(plumbing.CommitObject, h) +func objectExists(s storer.EncodedObjectStorer, h plumbing.Hash) (bool, error) { + _, err := s.EncodedObject(plumbing.AnyObject, h) if err == plumbing.ErrObjectNotFound { return false, nil } diff --git a/remote_test.go b/remote_test.go index 02ff690..7f40979 100644 --- a/remote_test.go +++ b/remote_test.go @@ -171,6 +171,17 @@ func (s *RemoteSuite) TestFetchWithPackfileWriter(c *C) { func (s *RemoteSuite) TestFetchNoErrAlreadyUpToDate(c *C) { url := s.GetBasicLocalRepositoryURL() + s.doTestFetchNoErrAlreadyUpToDate(c, url) +} + +func (s *RemoteSuite) TestFetchNoErrAlreadyUpToDateWithNonCommitObjects(c *C) { + fixture := fixtures.ByTag("tags").One() + url := s.GetLocalRepositoryURL(fixture) + s.doTestFetchNoErrAlreadyUpToDate(c, url) +} + +func (s *RemoteSuite) doTestFetchNoErrAlreadyUpToDate(c *C, url string) { + sto := memory.NewStorage() r := newRemote(sto, nil, &config.RemoteConfig{Name: "foo", URL: url}) -- cgit