From 21f106e6647ce70d1d40df65cd85e2e86264d2f0 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Sun, 10 May 2020 11:02:21 +0200 Subject: config: RefSpec.IsExactSHA1, validates if the refspec describes an exact SHA1 ref --- config/refspec_test.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'config/refspec_test.go') diff --git a/config/refspec_test.go b/config/refspec_test.go index b9c43b2..3be7573 100644 --- a/config/refspec_test.go +++ b/config/refspec_test.go @@ -3,8 +3,8 @@ package config import ( "testing" - . "gopkg.in/check.v1" "github.com/go-git/go-git/v5/plumbing" + . "gopkg.in/check.v1" ) type RefSpecSuite struct{} @@ -37,6 +37,12 @@ func (s *RefSpecSuite) TestRefSpecIsValid(c *C) { spec = RefSpec("refs/heads:") c.Assert(spec.Validate(), Equals, ErrRefSpecMalformedSeparator) + + spec = RefSpec("12039e008f9a4e3394f3f94f8ea897785cb09448:refs/heads/foo") + c.Assert(spec.Validate(), Equals, nil) + + spec = RefSpec("12039e008f9a4e3394f3f94f8ea897785cb09448:refs/heads/*") + c.Assert(spec.Validate(), Equals, ErrRefSpecMalformedWildcard) } func (s *RefSpecSuite) TestRefSpecIsForceUpdate(c *C) { @@ -58,6 +64,14 @@ func (s *RefSpecSuite) TestRefSpecIsDelete(c *C) { c.Assert(spec.IsDelete(), Equals, false) } +func (s *RefSpecSuite) TestRefSpecIsExactSHA1(c *C) { + spec := RefSpec("foo:refs/heads/master") + c.Assert(spec.IsExactSHA1(), Equals, false) + + spec = RefSpec("12039e008f9a4e3394f3f94f8ea897785cb09448:refs/heads/foo") + c.Assert(spec.IsExactSHA1(), Equals, true) +} + func (s *RefSpecSuite) TestRefSpecSrc(c *C) { spec := RefSpec("refs/heads/*:refs/remotes/origin/*") c.Assert(spec.Src(), Equals, "refs/heads/*") -- cgit