diff options
-rw-r--r-- | plumbing/protocol/packp/advrefs.go | 8 | ||||
-rw-r--r-- | plumbing/protocol/packp/advrefs_test.go | 24 | ||||
-rw-r--r-- | plumbing/transport/internal/common/common.go | 7 |
3 files changed, 30 insertions, 9 deletions
diff --git a/plumbing/protocol/packp/advrefs.go b/plumbing/protocol/packp/advrefs.go index ab286c6..1bd724c 100644 --- a/plumbing/protocol/packp/advrefs.go +++ b/plumbing/protocol/packp/advrefs.go @@ -201,3 +201,11 @@ func (a *AdvRefs) addSymbolicRefs(s storer.ReferenceStorer) error { func (a *AdvRefs) supportSymrefs() bool { return a.Capabilities.Supports(capability.SymRef) } + +// IsEmpty returns true if doesn't contain any reference. +func (a *AdvRefs) IsEmpty() bool { + return a.Head == nil && + len(a.References) == 0 && + len(a.Peeled) == 0 && + len(a.Shallows) == 0 +} diff --git a/plumbing/protocol/packp/advrefs_test.go b/plumbing/protocol/packp/advrefs_test.go index d37f127..d163e1f 100644 --- a/plumbing/protocol/packp/advrefs_test.go +++ b/plumbing/protocol/packp/advrefs_test.go @@ -79,6 +79,11 @@ func (s *AdvRefSuite) TestAllReferencesBadSymref(c *C) { c.Assert(err, NotNil) } +func (s *AdvRefSuite) TestIsEmpty(c *C) { + a := NewAdvRefs() + c.Assert(a.IsEmpty(), Equals, true) +} + func (s *AdvRefSuite) TestNoSymRefCapabilityHeadToMaster(c *C) { a := NewAdvRefs() headHash := plumbing.NewHash("5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c") @@ -156,7 +161,7 @@ type AdvRefsDecodeEncodeSuite struct{} var _ = Suite(&AdvRefsDecodeEncodeSuite{}) -func (s *AdvRefsDecodeEncodeSuite) test(c *C, in []string, exp []string) { +func (s *AdvRefsDecodeEncodeSuite) test(c *C, in []string, exp []string, isEmpty bool) { var err error var input io.Reader { @@ -181,6 +186,7 @@ func (s *AdvRefsDecodeEncodeSuite) test(c *C, in []string, exp []string) { { ar := NewAdvRefs() c.Assert(ar.Decode(input), IsNil) + c.Assert(ar.IsEmpty(), Equals, isEmpty) var buf bytes.Buffer c.Assert(ar.Encode(&buf), IsNil) @@ -202,7 +208,7 @@ func (s *AdvRefsDecodeEncodeSuite) TestNoHead(c *C) { pktline.FlushString, } - s.test(c, input, expected) + s.test(c, input, expected, true) } func (s *AdvRefsDecodeEncodeSuite) TestNoHeadSmart(c *C) { @@ -218,7 +224,7 @@ func (s *AdvRefsDecodeEncodeSuite) TestNoHeadSmart(c *C) { pktline.FlushString, } - s.test(c, input, expected) + s.test(c, input, expected, true) } func (s *AdvRefsDecodeEncodeSuite) TestNoHeadSmartBug(c *C) { @@ -236,7 +242,7 @@ func (s *AdvRefsDecodeEncodeSuite) TestNoHeadSmartBug(c *C) { pktline.FlushString, } - s.test(c, input, expected) + s.test(c, input, expected, true) } func (s *AdvRefsDecodeEncodeSuite) TestRefs(c *C) { @@ -256,7 +262,7 @@ func (s *AdvRefsDecodeEncodeSuite) TestRefs(c *C) { pktline.FlushString, } - s.test(c, input, expected) + s.test(c, input, expected, false) } func (s *AdvRefsDecodeEncodeSuite) TestPeeled(c *C) { @@ -280,7 +286,7 @@ func (s *AdvRefsDecodeEncodeSuite) TestPeeled(c *C) { pktline.FlushString, } - s.test(c, input, expected) + s.test(c, input, expected, false) } func (s *AdvRefsDecodeEncodeSuite) TestAll(c *C) { @@ -308,7 +314,7 @@ func (s *AdvRefsDecodeEncodeSuite) TestAll(c *C) { pktline.FlushString, } - s.test(c, input, expected) + s.test(c, input, expected, false) } func (s *AdvRefsDecodeEncodeSuite) TestAllSmart(c *C) { @@ -340,7 +346,7 @@ func (s *AdvRefsDecodeEncodeSuite) TestAllSmart(c *C) { pktline.FlushString, } - s.test(c, input, expected) + s.test(c, input, expected, false) } func (s *AdvRefsDecodeEncodeSuite) TestAllSmartBug(c *C) { @@ -372,7 +378,7 @@ func (s *AdvRefsDecodeEncodeSuite) TestAllSmartBug(c *C) { pktline.FlushString, } - s.test(c, input, expected) + s.test(c, input, expected, false) } func ExampleAdvRefs_Decode() { diff --git a/plumbing/transport/internal/common/common.go b/plumbing/transport/internal/common/common.go index d564d25..89432e3 100644 --- a/plumbing/transport/internal/common/common.go +++ b/plumbing/transport/internal/common/common.go @@ -175,6 +175,13 @@ func (s *session) AdvertisedReferences() (*packp.AdvRefs, error) { } } + // Some servers like jGit, announce capabilities instead of returning an + // packp message with a flush. This verifies that we received a empty + // adv-refs, even it contains capabilities. + if !s.isReceivePack && ar.IsEmpty() { + return nil, transport.ErrEmptyRemoteRepository + } + transport.FilterUnsupportedCapabilities(ar.Capabilities) s.advRefs = ar return ar, nil |