Skip to content

Commit

Permalink
Merge pull request #932 from aymanbagabas/fix-empty
Browse files Browse the repository at this point in the history
plumbing: fix empty uploadpack request error
  • Loading branch information
pjbgf committed Nov 17, 2023
2 parents 226d25b + 05551b7 commit 6d62dd1
Show file tree
Hide file tree
Showing 3 changed files with 24 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
14 changes: 14 additions & 0 deletions worktree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,20 @@ func (s *WorktreeSuite) TestPullAlreadyUptodate(c *C) {
c.Assert(err, Equals, NoErrAlreadyUpToDate)
}

func (s *WorktreeSuite) TestPullDepth(c *C) {
r, err := Clone(memory.NewStorage(), memfs.New(), &CloneOptions{
URL: fixtures.Basic().One().URL,
Depth: 1,
})

c.Assert(err, IsNil)

w, err := r.Worktree()
c.Assert(err, IsNil)
err = w.Pull(&PullOptions{})
c.Assert(err, Equals, nil)
}

func (s *WorktreeSuite) TestCheckout(c *C) {
fs := memfs.New()
w := &Worktree{
Expand Down

0 comments on commit 6d62dd1

Please sign in to comment.