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

Commit 443abf8

Browse files
authored
Merge pull request #1031 from jfontan/fix/error-fetching
git: return better error message when packfile cannot be downloaded
2 parents 8f52c50 + a4278c1 commit 443abf8

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

plumbing/format/packfile/common.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ func WritePackfileToObjectStorage(
5151
}
5252

5353
defer ioutil.CheckClose(w, &err)
54-
_, err = io.Copy(w, packfile)
54+
55+
var n int64
56+
n, err = io.Copy(w, packfile)
57+
if err == nil && n == 0 {
58+
return ErrEmptyPackfile
59+
}
60+
5561
return err
5662
}
5763

plumbing/format/packfile/common_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
package packfile
22

33
import (
4+
"bytes"
45
"testing"
56

67
"gopkg.in/src-d/go-git.v4/plumbing"
8+
"gopkg.in/src-d/go-git.v4/storage/memory"
79

810
. "gopkg.in/check.v1"
911
)
1012

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

15+
type CommonSuite struct{}
16+
17+
var _ = Suite(&CommonSuite{})
18+
19+
func (s *CommonSuite) TestEmptyUpdateObjectStorage(c *C) {
20+
var buf bytes.Buffer
21+
sto := memory.NewStorage()
22+
23+
err := UpdateObjectStorage(sto, &buf)
24+
c.Assert(err, Equals, ErrEmptyPackfile)
25+
}
26+
1327
func newObject(t plumbing.ObjectType, cont []byte) plumbing.EncodedObject {
1428
o := plumbing.MemoryObject{}
1529
o.SetType(t)

repository.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ var (
4141
ErrTagExists = errors.New("tag already exists")
4242
// ErrTagNotFound an error stating the specified tag does not exist
4343
ErrTagNotFound = errors.New("tag not found")
44+
// ErrFetching is returned when the packfile could not be downloaded
45+
ErrFetching = errors.New("unable to fetch packfile")
4446

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

0 commit comments

Comments
 (0)