From fdc18d60b0e0eb7c0df2cdba03e081fee3e7292c Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Fri, 30 Nov 2018 13:07:57 +0100 Subject: git: return better error message when packfile cannot be downloaded Previously the error message when the connection was closed while fetching was "object not found" and was misleading. Now when the packfile size is 0 the error "unable to fetch packfile" is returned. Signed-off-by: Javi Fontan --- plumbing/format/packfile/common.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'plumbing/format') diff --git a/plumbing/format/packfile/common.go b/plumbing/format/packfile/common.go index 2b4aceb..0d9ed54 100644 --- a/plumbing/format/packfile/common.go +++ b/plumbing/format/packfile/common.go @@ -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 } -- cgit From a4278c1c081578055c1e4df96aef54257729a100 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Mon, 3 Dec 2018 12:38:31 +0100 Subject: plumbing/packfile: test UpdateObjectStorage empty packfile error Signed-off-by: Javi Fontan --- plumbing/format/packfile/common_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'plumbing/format') diff --git a/plumbing/format/packfile/common_test.go b/plumbing/format/packfile/common_test.go index 387c0d1..eafc617 100644 --- a/plumbing/format/packfile/common_test.go +++ b/plumbing/format/packfile/common_test.go @@ -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) -- cgit