diff options
author | Javi Fontan <jfontan@gmail.com> | 2018-11-30 13:07:57 +0100 |
---|---|---|
committer | Javi Fontan <jfontan@gmail.com> | 2018-11-30 13:11:44 +0100 |
commit | fdc18d60b0e0eb7c0df2cdba03e081fee3e7292c (patch) | |
tree | a104cab678cfa181dbea5f7917b6eef6b848b67d | |
parent | 8f52c5099e7fe4a2519920a7bbf5a9bb52ff9cec (diff) | |
download | go-git-fdc18d60b0e0eb7c0df2cdba03e081fee3e7292c.tar.gz |
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 <jfontan@gmail.com>
-rw-r--r-- | plumbing/format/packfile/common.go | 8 | ||||
-rw-r--r-- | repository.go | 4 |
2 files changed, 11 insertions, 1 deletions
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 } diff --git a/repository.go b/repository.go index 97134ec..1f64b9f 100644 --- a/repository.go +++ b/repository.go @@ -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") @@ -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 } |