Skip to content

Commit

Permalink
git: return better error message when packfile cannot be downloaded
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jfontan committed Nov 30, 2018
1 parent 8f52c50 commit fdc18d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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
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

0 comments on commit fdc18d6

Please sign in to comment.