From 05551b70f689944ab558a2b326b2174f313d372a Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Thu, 16 Nov 2023 11:28:02 -0500 Subject: plumbing: fix empty uploadpack request error 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: https://github.com/go-git/go-git/issues/328 Fixes: https://github.com/go-git/go-git/issues/638 Fixes: https://github.com/go-git/go-git/issues/157 --- plumbing/transport/internal/common/common.go | 6 ++++++ remote.go | 4 ++++ worktree_test.go | 14 ++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/plumbing/transport/internal/common/common.go b/plumbing/transport/internal/common/common.go index 6574116..da1c2ac 100644 --- a/plumbing/transport/internal/common/common.go +++ b/plumbing/transport/internal/common/common.go @@ -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 } diff --git a/remote.go b/remote.go index 2b4122e..8ca9b10 100644 --- a/remote.go +++ b/remote.go @@ -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 } diff --git a/worktree_test.go b/worktree_test.go index 712695a..180bfb0 100644 --- a/worktree_test.go +++ b/worktree_test.go @@ -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{ -- cgit