From 8da17c50469f0864e710faf9d068ce2abe1f92fc Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 24 Aug 2010 17:35:52 -0700 Subject: [PATCH] Support parsing git describe style output We now match on the -gABBREV style output created by git describe when its describing a non-tagged commit, and resolve that back to the full ObjectId using the abbreviation resolution feature that we already support. Change-Id: Ib3033f9483d9e1c66c8bb721ff48d4485bcdaef1 Signed-off-by: Shawn O. Pearce --- .../jgit/lib/RepositoryResolveTest.java | 20 +++++++ .../src/org/eclipse/jgit/lib/Repository.java | 60 ++++++++++++++----- 2 files changed, 64 insertions(+), 16 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 c6ab8ba4f..4ca9ba020 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 @@ -48,6 +48,8 @@ package org.eclipse.jgit.lib; import java.io.IOException; +import org.eclipse.jgit.errors.IncorrectObjectTypeException; + public class RepositoryResolveTest extends SampleDataRepositoryTestCase { public void testObjectId_existing() throws IOException { @@ -140,4 +142,22 @@ public class RepositoryResolveTest extends SampleDataRepositoryTestCase { assertEquals("856ec208ae6cadac25a6d74f19b12bb27a24fe24",db.resolve("refs/tags/B10th^{tree}").name()); } + public void testParseGitDescribeOutput() throws IOException { + ObjectId exp = db.resolve("b"); + assertEquals(exp, db.resolve("B-g7f82283")); // old style + assertEquals(exp, db.resolve("B-6-g7f82283")); // new style + + assertEquals(exp, db.resolve("B-6-g7f82283^0")); + assertEquals(exp, db.resolve("B-6-g7f82283^{commit}")); + + try { + db.resolve("B-6-g7f82283^{blob}"); + fail("expected IncorrectObjectTypeException"); + } catch (IncorrectObjectTypeException badType) { + // Expected + } + + assertEquals(db.resolve("b^1"), db.resolve("B-6-g7f82283^1")); + assertEquals(db.resolve("b~2"), db.resolve("B-6-g7f82283~2")); + } } 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 078b293f4..8a0420568 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java @@ -375,8 +375,6 @@ public abstract class Repository { * Currently supported is combinations of these. *