Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 3962b8d

Browse files
authored
config: support delete refspecs (IsDelete). (#166)
1 parent a91727b commit 3962b8d

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

config/refspec.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ func (s RefSpec) IsForceUpdate() bool {
4848
return false
4949
}
5050

51+
// IsDelete returns true if the refspec indicates a delete (empty src).
52+
func (s RefSpec) IsDelete() bool {
53+
if s[0] == refSpecSeparator[0] {
54+
return true
55+
}
56+
57+
return false
58+
}
59+
5160
// Src return the src side
5261
func (s RefSpec) Src() string {
5362
spec := string(s)

config/refspec_test.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ func (s *RefSpecSuite) TestRefSpecIsValid(c *C) {
2323
spec = RefSpec("refs/heads/master:refs/remotes/origin/master")
2424
c.Assert(spec.IsValid(), Equals, true)
2525

26+
spec = RefSpec(":refs/heads/master")
27+
c.Assert(spec.IsValid(), Equals, true)
28+
29+
spec = RefSpec(":refs/heads/*")
30+
c.Assert(spec.IsValid(), Equals, false)
31+
32+
spec = RefSpec(":*")
33+
c.Assert(spec.IsValid(), Equals, false)
34+
2635
spec = RefSpec("refs/heads/*")
2736
c.Assert(spec.IsValid(), Equals, false)
2837
}
@@ -35,18 +44,36 @@ func (s *RefSpecSuite) TestRefSpecIsForceUpdate(c *C) {
3544
c.Assert(spec.IsForceUpdate(), Equals, false)
3645
}
3746

47+
func (s *RefSpecSuite) TestRefSpecIsDelete(c *C) {
48+
spec := RefSpec(":refs/heads/master")
49+
c.Assert(spec.IsDelete(), Equals, true)
50+
51+
spec = RefSpec("+refs/heads/*:refs/remotes/origin/*")
52+
c.Assert(spec.IsDelete(), Equals, false)
53+
54+
spec = RefSpec("refs/heads/*:refs/remotes/origin/*")
55+
c.Assert(spec.IsDelete(), Equals, false)
56+
}
57+
3858
func (s *RefSpecSuite) TestRefSpecSrc(c *C) {
3959
spec := RefSpec("refs/heads/*:refs/remotes/origin/*")
4060
c.Assert(spec.Src(), Equals, "refs/heads/*")
61+
62+
spec = RefSpec(":refs/heads/master")
63+
c.Assert(spec.Src(), Equals, "")
4164
}
4265

4366
func (s *RefSpecSuite) TestRefSpecMatch(c *C) {
4467
spec := RefSpec("refs/heads/master:refs/remotes/origin/master")
4568
c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/foo")), Equals, false)
4669
c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/master")), Equals, true)
70+
71+
spec = RefSpec(":refs/heads/master")
72+
c.Assert(spec.Match(plumbing.ReferenceName("")), Equals, true)
73+
c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/master")), Equals, false)
4774
}
4875

49-
func (s *RefSpecSuite) TestRefSpecMatchBlob(c *C) {
76+
func (s *RefSpecSuite) TestRefSpecMatchGlob(c *C) {
5077
spec := RefSpec("refs/heads/*:refs/remotes/origin/*")
5178
c.Assert(spec.Match(plumbing.ReferenceName("refs/tag/foo")), Equals, false)
5279
c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/foo")), Equals, true)

0 commit comments

Comments
 (0)