diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2020-04-07 09:37:34 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2020-04-07 09:37:34 +0200 |
commit | 7f7ab529081953fb91783301b5f4eb3c5d2dfdb0 (patch) | |
tree | cabd1ddd923bac0ac052b0187a35469a00cf368a /plumbing/protocol | |
parent | e04168bb11a960018b6bbabd6972fd33163b6f28 (diff) | |
download | go-git-7f7ab529081953fb91783301b5f4eb3c5d2dfdb0.tar.gz |
plumbing: transport, fix handling of empty adv-refs on upload-pack
Diffstat (limited to 'plumbing/protocol')
-rw-r--r-- | plumbing/protocol/packp/advrefs.go | 8 | ||||
-rw-r--r-- | plumbing/protocol/packp/advrefs_test.go | 24 |
2 files changed, 23 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() { |