Skip to content

Commit dd4e2b7

Browse files
authored
Merge pull request go-git#792 from AriehSchneier/empty-fetch-with-shallows
plumbing: packp, A request is not empty if it contains shallows. Fixes go-git#328
2 parents 99ccca6 + 025e131 commit dd4e2b7

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

plumbing/protocol/packp/uppackreq.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ func NewUploadPackRequestFromCapabilities(adv *capability.List) *UploadPackReque
3838
}
3939
}
4040

41-
// IsEmpty a request if empty if Haves are contained in the Wants, or if Wants
42-
// length is zero
41+
// IsEmpty returns whether a request is empty - it is empty if Haves are contained
42+
// in the Wants, or if Wants length is zero, and we don't have any shallows
4343
func (r *UploadPackRequest) IsEmpty() bool {
44-
return isSubset(r.Wants, r.Haves)
44+
return isSubset(r.Wants, r.Haves) && len(r.Shallows) == 0
4545
}
4646

4747
func isSubset(needle []plumbing.Hash, haystack []plumbing.Hash) bool {

plumbing/protocol/packp/uppackreq_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ func (s *UploadPackRequestSuite) TestIsEmpty(c *C) {
4141
r.Haves = append(r.Haves, plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c"))
4242

4343
c.Assert(r.IsEmpty(), Equals, true)
44+
45+
r = NewUploadPackRequest()
46+
r.Wants = append(r.Wants, plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c"))
47+
r.Haves = append(r.Haves, plumbing.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c"))
48+
r.Shallows = append(r.Shallows, plumbing.NewHash("2b41ef280fdb67a9b250678686a0c3e03b0a9989"))
49+
50+
c.Assert(r.IsEmpty(), Equals, false)
4451
}
4552

4653
type UploadHavesSuite struct{}

plumbing/transport/internal/common/common.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func (s *session) handleAdvRefDecodeError(err error) error {
232232
// UploadPack performs a request to the server to fetch a packfile. A reader is
233233
// returned with the packfile content. The reader must be closed after reading.
234234
func (s *session) UploadPack(ctx context.Context, req *packp.UploadPackRequest) (*packp.UploadPackResponse, error) {
235-
if req.IsEmpty() && len(req.Shallows) == 0 {
235+
if req.IsEmpty() {
236236
return nil, transport.ErrEmptyUploadPackRequest
237237
}
238238

0 commit comments

Comments
 (0)