Skip to content

Commit 99ccca6

Browse files
authored
Merge pull request go-git#802 from pjbgf/fix-build
plumbing: http, Fix empty repos on Git v2.41+
2 parents 4e1b9c8 + abe4919 commit 99ccca6

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

plumbing/protocol/packp/advrefs_decode.go

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ func decodeFirstHash(p *advRefsDecoder) decoderStateFn {
133133
return nil
134134
}
135135

136+
// TODO: Use object-format (when available) for hash size. Git 2.41+
136137
if len(p.line) < hashSize {
137138
p.error("cannot read hash, pkt-line too short")
138139
return nil

plumbing/protocol/packp/advrefs_decode_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,16 @@ func (s *AdvRefsDecodeSuite) TestCaps(c *C) {
218218
{Name: capability.SymRef, Values: []string{"HEAD:refs/heads/master"}},
219219
{Name: capability.Agent, Values: []string{"foo=bar"}},
220220
},
221+
}, {
222+
input: []string{
223+
"0000000000000000000000000000000000000000 capabilities^{}\x00report-status report-status-v2 delete-refs side-band-64k quiet atomic ofs-delta object-format=sha1 agent=git/2.41.0\n",
224+
pktline.FlushString,
225+
},
226+
capabilities: []entry{
227+
{Name: capability.ReportStatus, Values: []string(nil)},
228+
{Name: capability.ObjectFormat, Values: []string{"sha1"}},
229+
{Name: capability.Agent, Values: []string{"git/2.41.0"}},
230+
},
221231
}} {
222232
ar := s.testDecodeOK(c, test.input)
223233
for _, fixCap := range test.capabilities {

plumbing/transport/http/common.go

+11
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ func advertisedReferences(ctx context.Context, s *session, serviceName string) (
7373
return nil, err
7474
}
7575

76+
// Git 2.41+ returns a zero-id plus capabilities when an empty
77+
// repository is being cloned. This skips the existing logic within
78+
// advrefs_decode.decodeFirstHash, which expects a flush-pkt instead.
79+
//
80+
// This logic aligns with plumbing/transport/internal/common/common.go.
81+
if ar.IsEmpty() &&
82+
// Empty repositories are valid for git-receive-pack.
83+
transport.ReceivePackServiceName != serviceName {
84+
return nil, transport.ErrEmptyRemoteRepository
85+
}
86+
7687
transport.FilterUnsupportedCapabilities(ar.Capabilities)
7788
s.advRefs = ar
7889

remote.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,13 @@ func (r *Remote) PushContext(ctx context.Context, o *PushOptions) (err error) {
224224
return err
225225
}
226226

227-
if err = rs.Error(); err != nil {
228-
return err
227+
if rs != nil {
228+
if err = rs.Error(); err != nil {
229+
return err
230+
}
229231
}
230232

231-
return r.updateRemoteReferenceStorage(req, rs)
233+
return r.updateRemoteReferenceStorage(req)
232234
}
233235

234236
func (r *Remote) useRefDeltas(ar *packp.AdvRefs) bool {
@@ -347,7 +349,6 @@ func (r *Remote) newReferenceUpdateRequest(
347349

348350
func (r *Remote) updateRemoteReferenceStorage(
349351
req *packp.ReferenceUpdateRequest,
350-
result *packp.ReportStatus,
351352
) error {
352353

353354
for _, spec := range r.c.Fetch {

0 commit comments

Comments
 (0)