git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH 1/2] Issue 23: Resolve tag^0 as tag^{commit}

From
Jonas Fonseca <fonseca@diku.dk>
Date
Sep 11, 2008, 21:39 UTC
Message-ID
<20080911213927.GA20238@diku.dk>

Repository.resolve("tag^0") failed with "not a commit". Fix it and add a test case for it.

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
---
 .../org/spearce/jgit/lib/T0008_testparserev.java   |    9 ++++++++-
 .../src/org/spearce/jgit/lib/Repository.java       |    5 +++++
 2 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0008_testparserev.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0008_testparserev.java
index 8883b8b..3457574 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0008_testparserev.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/T0008_testparserev.java
@@ -109,10 +109,17 @@ public void testDerefTag() throws IOException {
 		assertEquals("fd608fbe625a2b456d9f15c2b1dc41f252057dd7",db.resolve("spearce-gpg-pub^{blob}").name());
 	}
 
+	public void testDerefTagIssue23() throws IOException {
+		assertEquals("17768080a2318cd89bba4c8b87834401e2095703",db.resolve("refs/tags/B").name());
+		assertEquals("d86a2aada2f5e7ccf6f11880bfb9ab404e8a8864",db.resolve("refs/tags/B^{commit}").name());
+		// The special tag^0 == tag^{commit} rule
+		assertEquals("d86a2aada2f5e7ccf6f11880bfb9ab404e8a8864",db.resolve("refs/tags/B^0").name());
+	}
+
 	public void testDerefBlob() throws IOException {
 		assertEquals("fd608fbe625a2b456d9f15c2b1dc41f252057dd7",db.resolve("fd608fbe625a2b456d9f15c2b1dc41f252057dd7^{}").name());
 		assertEquals("fd608fbe625a2b456d9f15c2b1dc41f252057dd7",db.resolve("fd608fbe625a2b456d9f15c2b1dc41f252057dd7^{blob}").name());
 	}
-	
+
 	// TODO: ^{tree} for a tag pointing to a tag
 }
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
index b27c23d..260a39d 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
@@ -562,6 +562,11 @@ public ObjectId resolve(final String revstr) throws IOException {
 					case '9':
 						int j;
 						ref = mapObject(refId, null);
+						if (ref instanceof Tag && rev[i + 1] == '0') {
+							Tag tag = (Tag)ref;
+							refId = tag.getObjId();
+							ref = mapObject(refId, null);
+						}
 						if (!(ref instanceof Commit))
 							throw new IncorrectObjectTypeException(refId, Constants.TYPE_COMMIT);
 						for (j=i+1; j<rev.length; ++j) {
-- 
1.6.0.336.ga07ba


-- 
Jonas Fonseca
Next: Robin Rosenberg
Message 1 of 10 in “Issue 23: Resolve tag^0 as tag^{commit}”
  1. 1/2 Issue 23: Resolve tag^0 as tag^{commit}Jonas Fonseca, Sep 11, 2008
  2. Robin RosenbergSep 11, 2008
  3. Jonas FonsecaSep 12, 2008
  4. Imran M YousufSep 12, 2008
  5. Configure the maven surefire plugin to specifically include all testsJonas Fonseca, Sep 12, 2008
  6. Shawn O. PearceSep 12, 2008
  7. Robin RosenbergSep 12, 2008
  8. 1/3 Fix IncorrectObjectTypeException thrown for incorrect ^{blob}Jonas Fonseca, Sep 12, 2008
  9. 2/3 Fix off by one distance during resolving of commit~NJonas Fonseca, Sep 12, 2008
  10. 3/3 Tests and fixes for dereferencing tags in Repository.resolve()Jonas Fonseca, Sep 12, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.