diff options
author | Dave Borowitz <dborowitz@google.com> | 2012-09-18 19:49:35 +0200 |
---|---|---|
committer | Robin Rosenberg <robin.rosenberg@dewire.com> | 2012-09-18 19:51:57 +0200 |
commit | 70ae16d708e0a207035872a16943f8b9151f33cd (patch) | |
tree | c4b81dd91f6d1d76808de361b108fd8e97182b63 | |
parent | a551493240d5513a101415e55742c689562d6f51 (diff) | |
download | jgit-70ae16d708e0a207035872a16943f8b9151f33cd.tar.gz jgit-70ae16d708e0a207035872a16943f8b9151f33cd.zip |
Fix resolving expression with ~ and ^ than extends beyond history
resolve("foo~X") where X is greater than the distance from foo to the
root should return null, but 2a2362fb introduced a bug causing it to
either return resolve("foo") or NPE. Add a test for the correct
behavior.
Also add an analogous test for foo^X where X is greater than the
number of parents (which was not broken by that commit).
Change-Id: Ic580081ece57c8c2df29b652897b425ecb34e11f
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java | 23 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java | 5 |
2 files changed, 27 insertions, 1 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 deb830ff5b..defd93b107 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 @@ -100,6 +100,15 @@ public class RepositoryResolveTest extends SampleDataRepositoryTestCase { } @Test + public void testObjectId_objectid_invalid_explicit_parent() throws IOException { + assertEquals("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1",db.resolve("6462e7d8024396b14d7651e2ec11e2bbf07a05c4^1").name()); + assertNull(db.resolve("6462e7d8024396b14d7651e2ec11e2bbf07a05c4^2")); + assertEquals("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1",db.resolve("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1^0").name()); + assertNull(db.resolve("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1^1")); + assertNull(db.resolve("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1^2")); + } + + @Test public void testRef_refname() throws IOException { assertEquals("49322bb17d3acc9146f98c97d078513228bbf3c0",db.resolve("master^0").name()); assertEquals("6e1475206e57110fcef4b92320436c1e9872a322",db.resolve("master^").name()); @@ -121,6 +130,20 @@ public class RepositoryResolveTest extends SampleDataRepositoryTestCase { } @Test + public void testDistance_past_root() throws IOException { + assertEquals("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1",db.resolve("6462e7d8024396b14d7651e2ec11e2bbf07a05c4~1").name()); + assertNull(db.resolve("6462e7d8024396b14d7651e2ec11e2bbf07a05c4~~")); + assertNull(db.resolve("6462e7d8024396b14d7651e2ec11e2bbf07a05c4~2")); + assertNull(db.resolve("6462e7d8024396b14d7651e2ec11e2bbf07a05c4~99")); + assertNull(db.resolve("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1~~")); + assertNull(db.resolve("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1~2")); + assertNull(db.resolve("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1~99")); + assertEquals("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1",db.resolve("master~6").name()); + assertNull(db.resolve("master~7")); + assertNull(db.resolve("master~6~")); + } + + @Test public void testTree() throws IOException { assertEquals("6020a3b8d5d636e549ccbd0c53e2764684bb3125",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^{tree}").name()); assertEquals("02ba32d3649e510002c21651936b7077aa75ffa9",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^^{tree}").name()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java index 82394dd757..16f8cdfef7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java @@ -532,6 +532,7 @@ public abstract class Repository { if (name == null) name = new String(revChars, done, i); rev = parseSimple(rw, name); + name = null; if (rev == null) return null; } @@ -588,6 +589,7 @@ public abstract class Repository { // detached name = Constants.HEAD; Ref ref = getRef(name); + name = null; if (ref == null) return null; if (ref.isSymbolic()) @@ -635,6 +637,7 @@ public abstract class Repository { if (name.equals("")) name = Constants.HEAD; Ref ref = getRef(name); + name = null; if (ref == null) return null; // @{n} means current branch, not HEAD@{1} unless @@ -642,7 +645,6 @@ public abstract class Repository { if (ref.isSymbolic()) ref = ref.getLeaf(); rev = resolveReflog(rw, ref, time); - name = null; } i = m; } else @@ -656,6 +658,7 @@ public abstract class Repository { if (name.equals("")) name = Constants.HEAD; rev = parseSimple(rw, name); + name = null; } if (rev == null) return null; |