From: Matthias Sohn Date: Sun, 20 Feb 2022 11:03:22 +0000 (+0100) Subject: DescribeCommand: Add support for --abbrev=0 X-Git-Tag: v6.1.0.202203021511-rc1~1^2~8 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a2d5650b8fc6775cc8684550d205502c70ab8771;p=jgit.git DescribeCommand: Add support for --abbrev=0 Setting --abbrev=0 suppresses long format and only shows the closest tag [1]. [1] https://git-scm.com/docs/git-describe#Documentation/git-describe.txt---abbrevltngt Change-Id: Ifcf4d7786dd0f0fb0315d8093fdb54384ed9d5f9 --- diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java index 2051169996..48980ad6e4 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java @@ -102,6 +102,8 @@ public class DescribeCommandTest extends RepositoryTestCase { assertEquals("alice-t1-2-g3e563c5", describe(c4, "alice*")); assertEquals("bob-t2-1-g3e563c5", describe(c4, "bob*")); assertEquals("bob-t2-1-g3e563c5", describe(c4, "a*", "b*", "c*")); + + assertEquals("bob-t2", describe(c4, false, true, 0)); } else { assertEquals(null, describe(c2)); assertEquals(null, describe(c3)); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java index e572773e43..955d147691 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java @@ -227,6 +227,9 @@ public class DescribeCommand extends GitCommand { private String longDescription(Ref tag, int depth, ObjectId tip) throws IOException { + if (abbrev == 0) { + return formatRefName(tag.getName()); + } return String.format("%s-%d-g%s", formatRefName(tag.getName()), //$NON-NLS-1$ Integer.valueOf(depth), w.getObjectReader().abbreviate(tip, abbrev).name());