aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/protocol/packp/advrefs_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2018-04-02 10:40:53 +0200
committerGitHub <noreply@github.com>2018-04-02 10:40:53 +0200
commit2cbff8d8ffa42dd1b399b3c94d094bdb2d1cdf5c (patch)
tree97bc184a52e6b0b654416d36ca1f848221ccf414 /plumbing/protocol/packp/advrefs_test.go
parent32931400e23550cc840d2c2ae7bb5a20ef1946e7 (diff)
parent0b523020ef35b56c1f2481ca3773d974a7b80945 (diff)
downloadgo-git-2cbff8d8ffa42dd1b399b3c94d094bdb2d1cdf5c.tar.gz
Merge pull request #792 from ajnavarro/fix/support-no-symref-capability
Resolve HEAD if symRefs capability is not supported
Diffstat (limited to 'plumbing/protocol/packp/advrefs_test.go')
-rw-r--r--plumbing/protocol/packp/advrefs_test.go73
1 files changed, 73 insertions, 0 deletions
diff --git a/plumbing/protocol/packp/advrefs_test.go b/plumbing/protocol/packp/advrefs_test.go
index 0180fd3..bb8d032 100644
--- a/plumbing/protocol/packp/advrefs_test.go
+++ b/plumbing/protocol/packp/advrefs_test.go
@@ -79,6 +79,79 @@ func (s *AdvRefSuite) TestAllReferencesBadSymref(c *C) {
c.Assert(err, NotNil)
}
+func (s *AdvRefSuite) TestNoSymRefCapabilityHeadToMaster(c *C) {
+ a := NewAdvRefs()
+ headHash := plumbing.NewHash("5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c")
+ a.Head = &headHash
+ ref := plumbing.NewHashReference(plumbing.Master, plumbing.NewHash("5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c"))
+
+ err := a.AddReference(ref)
+ c.Assert(err, IsNil)
+
+ storage, err := a.AllReferences()
+ c.Assert(err, IsNil)
+
+ head, err := storage.Reference(plumbing.HEAD)
+ c.Assert(err, IsNil)
+ c.Assert(head.Target(), Equals, ref.Name())
+}
+
+func (s *AdvRefSuite) TestNoSymRefCapabilityHeadToOtherThanMaster(c *C) {
+ a := NewAdvRefs()
+ headHash := plumbing.NewHash("0000000000000000000000000000000000000000")
+ a.Head = &headHash
+ ref1 := plumbing.NewHashReference(plumbing.Master, plumbing.NewHash("5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c"))
+ ref2 := plumbing.NewHashReference("other/ref", plumbing.NewHash("0000000000000000000000000000000000000000"))
+
+ err := a.AddReference(ref1)
+ c.Assert(err, IsNil)
+ err = a.AddReference(ref2)
+ c.Assert(err, IsNil)
+
+ storage, err := a.AllReferences()
+ c.Assert(err, IsNil)
+
+ head, err := storage.Reference(plumbing.HEAD)
+ c.Assert(err, IsNil)
+ c.Assert(head.Hash(), Equals, ref2.Hash())
+}
+
+func (s *AdvRefSuite) TestNoSymRefCapabilityHeadToNoRef(c *C) {
+ a := NewAdvRefs()
+ headHash := plumbing.NewHash("0000000000000000000000000000000000000000")
+ a.Head = &headHash
+ ref := plumbing.NewHashReference(plumbing.Master, plumbing.NewHash("5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c"))
+
+ err := a.AddReference(ref)
+ c.Assert(err, IsNil)
+
+ _, err = a.AllReferences()
+ c.Assert(err, NotNil)
+}
+
+func (s *AdvRefSuite) TestNoSymRefCapabilityHeadToNoMasterAlphabeticallyOrdered(c *C) {
+ a := NewAdvRefs()
+ headHash := plumbing.NewHash("5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c")
+ a.Head = &headHash
+ ref1 := plumbing.NewHashReference(plumbing.Master, plumbing.NewHash("0000000000000000000000000000000000000000"))
+ ref2 := plumbing.NewHashReference("aaaaaaaaaaaaaaa", plumbing.NewHash("5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c"))
+ ref3 := plumbing.NewHashReference("bbbbbbbbbbbbbbb", plumbing.NewHash("5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c"))
+
+ err := a.AddReference(ref1)
+ c.Assert(err, IsNil)
+ err = a.AddReference(ref3)
+ c.Assert(err, IsNil)
+ err = a.AddReference(ref2)
+ c.Assert(err, IsNil)
+
+ storage, err := a.AllReferences()
+ c.Assert(err, IsNil)
+
+ head, err := storage.Reference(plumbing.HEAD)
+ c.Assert(err, IsNil)
+ c.Assert(head.Target(), Equals, ref2.Name())
+}
+
type AdvRefsDecodeEncodeSuite struct{}
var _ = Suite(&AdvRefsDecodeEncodeSuite{})