aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/protocol/packp/advrefs_test.go
diff options
context:
space:
mode:
authorAntonio Jesus Navarro Perez <antnavper@gmail.com>2018-03-26 18:07:09 +0200
committerAntonio Jesus Navarro Perez <antnavper@gmail.com>2018-03-26 18:14:01 +0200
commit0b523020ef35b56c1f2481ca3773d974a7b80945 (patch)
treea1f3f71629466757b3f8cab48bb96cd737ef9f4b /plumbing/protocol/packp/advrefs_test.go
parent160e6d5b654fbbaf0d9264f226c56a03f0e27d30 (diff)
downloadgo-git-0b523020ef35b56c1f2481ca3773d974a7b80945.tar.gz
Resolve HEAD if symRefs capability is not supported
Signed-off-by: Antonio Jesus Navarro Perez <antnavper@gmail.com>
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{})