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

Commit fdc18d6

Browse files
committed
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>
1 parent 8f52c50 commit fdc18d6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-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

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)