]> source.dussan.org Git - jgit.git/commitdiff
Fix resolving expression with ~ and ^ than extends beyond history 35/7735/3
authorDave Borowitz <dborowitz@google.com>
Tue, 18 Sep 2012 17:49:35 +0000 (19:49 +0200)
committerRobin Rosenberg <robin.rosenberg@dewire.com>
Tue, 18 Sep 2012 17:51:57 +0000 (19:51 +0200)
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

org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java

index deb830ff5bc4a6d5a57a6f4003adffaf0c0b9b80..defd93b10752b5e56be4ca16ba4bcf8bd56ac3ba 100644 (file)
@@ -99,6 +99,15 @@ public class RepositoryResolveTest extends SampleDataRepositoryTestCase {
                assertEquals("d0114ab8ac326bab30e3a657a0397578c5a1af88",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0^03").name());
        }
 
+       @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());
@@ -120,6 +129,20 @@ public class RepositoryResolveTest extends SampleDataRepositoryTestCase {
                assertEquals("1203b03dc816ccbb67773f28b3c19318654b0bc8",db.resolve("49322bb17d3acc9146f98c97d078513228bbf3c0~~~0").name());
        }
 
+       @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());
index 82394dd75709e64ac7dce9f67510e7f98ef60dec..16f8cdfef7f04d9e9fb5c86b1dc9d6ac77af25c4 100644 (file)
@@ -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;