diff options
-rw-r--r-- | config/refspec.go | 9 | ||||
-rw-r--r-- | config/refspec_test.go | 29 |
2 files changed, 37 insertions, 1 deletions
diff --git a/config/refspec.go b/config/refspec.go index fd0aa3d..9451170 100644 --- a/config/refspec.go +++ b/config/refspec.go @@ -48,6 +48,15 @@ func (s RefSpec) IsForceUpdate() bool { return false } +// IsDelete returns true if the refspec indicates a delete (empty src). +func (s RefSpec) IsDelete() bool { + if s[0] == refSpecSeparator[0] { + return true + } + + return false +} + // Src return the src side func (s RefSpec) Src() string { spec := string(s) diff --git a/config/refspec_test.go b/config/refspec_test.go index f0d1a0e..e0f052a 100644 --- a/config/refspec_test.go +++ b/config/refspec_test.go @@ -23,6 +23,15 @@ func (s *RefSpecSuite) TestRefSpecIsValid(c *C) { spec = RefSpec("refs/heads/master:refs/remotes/origin/master") c.Assert(spec.IsValid(), Equals, true) + spec = RefSpec(":refs/heads/master") + c.Assert(spec.IsValid(), Equals, true) + + spec = RefSpec(":refs/heads/*") + c.Assert(spec.IsValid(), Equals, false) + + spec = RefSpec(":*") + c.Assert(spec.IsValid(), Equals, false) + spec = RefSpec("refs/heads/*") c.Assert(spec.IsValid(), Equals, false) } @@ -35,18 +44,36 @@ func (s *RefSpecSuite) TestRefSpecIsForceUpdate(c *C) { c.Assert(spec.IsForceUpdate(), Equals, false) } +func (s *RefSpecSuite) TestRefSpecIsDelete(c *C) { + spec := RefSpec(":refs/heads/master") + c.Assert(spec.IsDelete(), Equals, true) + + spec = RefSpec("+refs/heads/*:refs/remotes/origin/*") + c.Assert(spec.IsDelete(), Equals, false) + + spec = RefSpec("refs/heads/*:refs/remotes/origin/*") + c.Assert(spec.IsDelete(), Equals, false) +} + func (s *RefSpecSuite) TestRefSpecSrc(c *C) { spec := RefSpec("refs/heads/*:refs/remotes/origin/*") c.Assert(spec.Src(), Equals, "refs/heads/*") + + spec = RefSpec(":refs/heads/master") + c.Assert(spec.Src(), Equals, "") } func (s *RefSpecSuite) TestRefSpecMatch(c *C) { spec := RefSpec("refs/heads/master:refs/remotes/origin/master") c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/foo")), Equals, false) c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/master")), Equals, true) + + spec = RefSpec(":refs/heads/master") + c.Assert(spec.Match(plumbing.ReferenceName("")), Equals, true) + c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/master")), Equals, false) } -func (s *RefSpecSuite) TestRefSpecMatchBlob(c *C) { +func (s *RefSpecSuite) TestRefSpecMatchGlob(c *C) { spec := RefSpec("refs/heads/*:refs/remotes/origin/*") c.Assert(spec.Match(plumbing.ReferenceName("refs/tag/foo")), Equals, false) c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/foo")), Equals, true) |