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
Fixes: go-git#157
  • Loading branch information
aymanbagabas committed Nov 16, 2023
1 parent 63b586b commit 05551b7
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 05551b7

Please sign in to comment.