aboutsummaryrefslogtreecommitdiffstats
path: root/config/refspec_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2019-06-17 04:32:50 +0200
committerGitHub <noreply@github.com>2019-06-17 04:32:50 +0200
commita35ce6e8ee8e0fc5449c0fd10d45d0bddc894edc (patch)
tree6fa78d446620685126239b18fdbafc1987be787b /config/refspec_test.go
parent26b54e8c7bc9678bf87c6ba298edf38d34b51d25 (diff)
parentaf3226f6522d5545c3aa546eb7c99ec131b38302 (diff)
downloadgo-git-a35ce6e8ee8e0fc5449c0fd10d45d0bddc894edc.tar.gz
Merge pull request #1160 from novas0x2a/fix-refspec
fix wildcard handling in RefSpec matching
Diffstat (limited to 'config/refspec_test.go')
-rw-r--r--config/refspec_test.go67
1 files changed, 59 insertions, 8 deletions
diff --git a/config/refspec_test.go b/config/refspec_test.go
index 675e075..2d2b057 100644
--- a/config/refspec_test.go
+++ b/config/refspec_test.go
@@ -96,9 +96,38 @@ func (s *RefSpecSuite) TestRefSpecMatch(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)
+ tests := map[string]map[string]bool{
+ "refs/heads/*:refs/remotes/origin/*": {
+ "refs/tag/foo": false,
+ "refs/heads/foo": true,
+ },
+ "refs/heads/*bc:refs/remotes/origin/*bc": {
+ "refs/heads/abc": true,
+ "refs/heads/bc": true,
+ "refs/heads/abx": false,
+ },
+ "refs/heads/a*c:refs/remotes/origin/a*c": {
+ "refs/heads/abc": true,
+ "refs/heads/ac": true,
+ "refs/heads/abx": false,
+ },
+ "refs/heads/ab*:refs/remotes/origin/ab*": {
+ "refs/heads/abc": true,
+ "refs/heads/ab": true,
+ "refs/heads/xbc": false,
+ },
+ }
+
+ for specStr, data := range tests {
+ spec := RefSpec(specStr)
+ for ref, matches := range data {
+ c.Assert(spec.Match(plumbing.ReferenceName(ref)),
+ Equals,
+ matches,
+ Commentf("while matching spec %q against ref %q", specStr, ref),
+ )
+ }
+ }
}
func (s *RefSpecSuite) TestRefSpecDst(c *C) {
@@ -110,11 +139,33 @@ func (s *RefSpecSuite) TestRefSpecDst(c *C) {
}
func (s *RefSpecSuite) TestRefSpecDstBlob(c *C) {
- spec := RefSpec("refs/heads/*:refs/remotes/origin/*")
- c.Assert(
- spec.Dst(plumbing.ReferenceName("refs/heads/foo")).String(), Equals,
- "refs/remotes/origin/foo",
- )
+ ref := "refs/heads/abc"
+ tests := map[string]string{
+ "refs/heads/*:refs/remotes/origin/*": "refs/remotes/origin/abc",
+ "refs/heads/*bc:refs/remotes/origin/*": "refs/remotes/origin/a",
+ "refs/heads/*bc:refs/remotes/origin/*bc": "refs/remotes/origin/abc",
+ "refs/heads/a*c:refs/remotes/origin/*": "refs/remotes/origin/b",
+ "refs/heads/a*c:refs/remotes/origin/a*c": "refs/remotes/origin/abc",
+ "refs/heads/ab*:refs/remotes/origin/*": "refs/remotes/origin/c",
+ "refs/heads/ab*:refs/remotes/origin/ab*": "refs/remotes/origin/abc",
+ "refs/heads/*abc:refs/remotes/origin/*abc": "refs/remotes/origin/abc",
+ "refs/heads/abc*:refs/remotes/origin/abc*": "refs/remotes/origin/abc",
+ // for these two cases, git specifically logs:
+ // error: * Ignoring funny ref 'refs/remotes/origin/' locally
+ // and ignores the ref; go-git does not currently do this validation,
+ // but probably should.
+ // "refs/heads/*abc:refs/remotes/origin/*": "",
+ // "refs/heads/abc*:refs/remotes/origin/*": "",
+ }
+
+ for specStr, dst := range tests {
+ spec := RefSpec(specStr)
+ c.Assert(spec.Dst(plumbing.ReferenceName(ref)).String(),
+ Equals,
+ dst,
+ Commentf("while getting dst from spec %q with ref %q", specStr, ref),
+ )
+ }
}
func (s *RefSpecSuite) TestMatchAny(c *C) {
specs := []RefSpec{