diff options
author | Robin Rosenberg <robin.rosenberg@dewire.com> | 2012-09-24 14:36:57 -0400 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2012-09-24 14:36:57 -0400 |
commit | bc66934a8317f4af1e8454560f8179a249026dcc (patch) | |
tree | c23e035a4e5ec57fefee5132672a97b6b647ef6f /org.eclipse.jgit.test | |
parent | 2e1d391f62579f77d97d7e1ec6ff53bb9146644d (diff) | |
parent | 094df5a916db6060fa7f7d8c1f61cc0b970a9433 (diff) | |
download | jgit-bc66934a8317f4af1e8454560f8179a249026dcc.tar.gz jgit-bc66934a8317f4af1e8454560f8179a249026dcc.zip |
Merge "Allow @ in branch names and tighten syntax checking"
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java index defd93b107..91364ce984 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java @@ -47,14 +47,18 @@ package org.eclipse.jgit.lib; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.IOException; import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.errors.AmbiguousObjectException; import org.eclipse.jgit.errors.IncorrectObjectTypeException; +import org.eclipse.jgit.errors.RevisionSyntaxException; import org.eclipse.jgit.revwalk.RevCommit; import org.junit.Test; @@ -133,9 +137,11 @@ public class RepositoryResolveTest extends SampleDataRepositoryTestCase { public void testDistance_past_root() throws IOException { assertEquals("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1",db.resolve("6462e7d8024396b14d7651e2ec11e2bbf07a05c4~1").name()); assertNull(db.resolve("6462e7d8024396b14d7651e2ec11e2bbf07a05c4~~")); + assertNull(db.resolve("6462e7d8024396b14d7651e2ec11e2bbf07a05c4^^")); assertNull(db.resolve("6462e7d8024396b14d7651e2ec11e2bbf07a05c4~2")); assertNull(db.resolve("6462e7d8024396b14d7651e2ec11e2bbf07a05c4~99")); assertNull(db.resolve("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1~~")); + assertNull(db.resolve("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1^^")); assertNull(db.resolve("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1~2")); assertNull(db.resolve("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1~99")); assertEquals("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1",db.resolve("master~6").name()); @@ -289,6 +295,53 @@ public class RepositoryResolveTest extends SampleDataRepositoryTestCase { assertEquals("refs/remotes/origin/main", db.simplify("@{upstream}")); } + @Test + public void invalidNames() throws AmbiguousObjectException, IOException { + assertTrue(Repository.isValidRefName("x/a")); + assertTrue(Repository.isValidRefName("x/a.b")); + assertTrue(Repository.isValidRefName("x/a@b")); + assertTrue(Repository.isValidRefName("x/a@b{x}")); + assertTrue(Repository.isValidRefName("x/a/b")); + assertTrue(Repository.isValidRefName("x/a]b")); // odd, yes.. + assertTrue(Repository.isValidRefName("x/\u00a0")); // unicode is fine, + // even hard space + assertFalse(Repository.isValidRefName("x/.a")); + assertFalse(Repository.isValidRefName("x/a.")); + assertFalse(Repository.isValidRefName("x/a..b")); + assertFalse(Repository.isValidRefName("x//a")); + assertFalse(Repository.isValidRefName("x/a/")); + assertFalse(Repository.isValidRefName("x/a//b")); + assertFalse(Repository.isValidRefName("x/a[b")); + assertFalse(Repository.isValidRefName("x/a^b")); + assertFalse(Repository.isValidRefName("x/a*b")); + assertFalse(Repository.isValidRefName("x/a?b")); + assertFalse(Repository.isValidRefName("x/a~1")); + assertFalse(Repository.isValidRefName("x/a\\b")); + assertFalse(Repository.isValidRefName("x/a\u0000")); + + assertUnparseable("."); + assertUnparseable("x@{3"); + assertUnparseable("x[b"); + assertUnparseable("x y"); + assertUnparseable("x."); + assertUnparseable(".x"); + assertUnparseable("a..b"); + assertUnparseable("x\\b"); + assertUnparseable("a~b"); + assertUnparseable("a^b"); + assertUnparseable("a\u0000"); + } + + private void assertUnparseable(String s) throws AmbiguousObjectException, + IOException { + try { + db.resolve(s); + fail("'" + s + "' should be unparseable"); + } catch (RevisionSyntaxException e) { + // good + } + } + private static ObjectId id(String name) { return ObjectId.fromString(name); } |