Skip to content

Commit

Permalink
plumbing: fix empty uploadpack request error
Browse files Browse the repository at this point in the history
If we have all what we asked for, finish the session and handle error.

This is equivalent of git "Already up to date." message.

Fixes: go-git#328
Fixes: go-git#638
  • Loading branch information
aymanbagabas committed Nov 16, 2023
1 parent 63b586b commit b610ab2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions plumbing/transport/internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ func (s *session) handleAdvRefDecodeError(err error) error {
// returned with the packfile content. The reader must be closed after reading.
func (s *session) UploadPack(ctx context.Context, req *packp.UploadPackRequest) (*packp.UploadPackResponse, error) {
if req.IsEmpty() {
// XXX: IsEmpty means haves are a subset of wants, in that case we have
// everything we asked for. Close the connection and return nil.
if err := s.finish(); err != nil {
return nil, err
}
// TODO:(v6) return nil here
return nil, transport.ErrEmptyUploadPackRequest
}

Expand Down
4 changes: 4 additions & 0 deletions remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,10 @@ func (r *Remote) fetchPack(ctx context.Context, o *FetchOptions, s transport.Upl

reader, err := s.UploadPack(ctx, req)
if err != nil {
if errors.Is(err, transport.ErrEmptyUploadPackRequest) {
// XXX: no packfile provided, everything is up-to-date.
return nil
}
return err
}

Expand Down

0 comments on commit b610ab2

Please sign in to comment.