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

git: return better error message when packfile cannot be downloaded #1031

Merged
merged 2 commits into from
Dec 4, 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
8 changes: 7 additions & 1 deletion plumbing/format/packfile/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ func WritePackfileToObjectStorage(
}

defer ioutil.CheckClose(w, &err)
_, err = io.Copy(w, packfile)

var n int64
n, err = io.Copy(w, packfile)
if err == nil && n == 0 {
return ErrEmptyPackfile
}

return err
}

Expand Down
14 changes: 14 additions & 0 deletions plumbing/format/packfile/common_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
package packfile

import (
"bytes"
"testing"

"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/storage/memory"

. "gopkg.in/check.v1"
)

func Test(t *testing.T) { TestingT(t) }

type CommonSuite struct{}

var _ = Suite(&CommonSuite{})

func (s *CommonSuite) TestEmptyUpdateObjectStorage(c *C) {
var buf bytes.Buffer
sto := memory.NewStorage()

err := UpdateObjectStorage(sto, &buf)
c.Assert(err, Equals, ErrEmptyPackfile)
}

func newObject(t plumbing.ObjectType, cont []byte) plumbing.EncodedObject {
o := plumbing.MemoryObject{}
o.SetType(t)
Expand Down
4 changes: 4 additions & 0 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ var (
ErrTagExists = errors.New("tag already exists")
// ErrTagNotFound an error stating the specified tag does not exist
ErrTagNotFound = errors.New("tag not found")
// ErrFetching is returned when the packfile could not be downloaded
ErrFetching = errors.New("unable to fetch packfile")

ErrInvalidReference = errors.New("invalid reference, should be a tag or a branch")
ErrRepositoryNotExists = errors.New("repository does not exist")
Expand Down Expand Up @@ -858,6 +860,8 @@ func (r *Repository) fetchAndUpdateReferences(
remoteRefs, err := remote.fetch(ctx, o)
if err == NoErrAlreadyUpToDate {
objsUpdated = false
} else if err == packfile.ErrEmptyPackfile {
return nil, ErrFetching
} else if err != nil {
return nil, err
}
Expand Down