From a2d3c376a682b540ecd87fe3ff2ffebc1766f938 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Fri, 22 Jul 2016 11:39:50 -0700 Subject: RefSpecs: allow construction of weird wildcarded RefSpecs Gerrit's superproject subscription feature uses RefSpecs to formalize the ACLs of when the superproject subscription feature is allowed. As this is a slightly different use case than describing a local/remote pair of refs, we need to be more permissive. Specifically we want to allow: refs/heads/* refs/heads/*:refs/heads/master refs/heads/master:refs/heads/* Introduce a new constructor, that allows constructing these RefSpecs. Change-Id: I46c0bea9d876e61eb2c8d50f404b905792bc72b3 Signed-off-by: Stefan Beller --- .../org/eclipse/jgit/transport/RefSpecTest.java | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RefSpecTest.java') diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RefSpecTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RefSpecTest.java index b14b0b3347..c9e44e768f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RefSpecTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RefSpecTest.java @@ -55,6 +55,7 @@ import static org.junit.Assert.assertTrue; import org.eclipse.jgit.lib.ObjectIdRef; import org.eclipse.jgit.lib.Ref; +import org.eclipse.jgit.transport.RefSpec.WildcardMode; import org.junit.Test; public class RefSpecTest { @@ -474,4 +475,28 @@ public class RefSpecTest { RefSpec a = new RefSpec("refs/heads/*:refs/remotes/origin/*"); a.setDestination("refs/remotes/origin/*/*"); } + + @Test + public void sourceOnlywithWildcard() { + RefSpec a = new RefSpec("refs/heads/*", + WildcardMode.ALLOW_MISMATCH); + assertTrue(a.matchSource("refs/heads/master")); + assertNull(a.getDestination()); + } + + @Test + public void destinationWithWildcard() { + RefSpec a = new RefSpec("refs/heads/master:refs/heads/*", + WildcardMode.ALLOW_MISMATCH); + assertTrue(a.matchSource("refs/heads/master")); + assertTrue(a.matchDestination("refs/heads/master")); + assertTrue(a.matchDestination("refs/heads/foo")); + } + + @Test + public void onlyWildCard() { + RefSpec a = new RefSpec("*", WildcardMode.ALLOW_MISMATCH); + assertTrue(a.matchSource("refs/heads/master")); + assertNull(a.getDestination()); + } } -- cgit v1.2.3