]> source.dussan.org Git - jgit.git/commitdiff
DescribeCommand: Add support for --abbrev=0 06/191006/2
authorMatthias Sohn <matthias.sohn@sap.com>
Sun, 20 Feb 2022 11:03:22 +0000 (12:03 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Wed, 2 Mar 2022 08:56:03 +0000 (09:56 +0100)
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

org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java
org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java

index 205116999608a50775daec9ea8cd6ca89320eb79..48980ad6e4dd04344a5fd08130418f6fc085f3d0 100644 (file)
@@ -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));
index e572773e430e5a61c1e3869fbd5a37773c2e868c..955d147691506da2d51c8284d1089081c10bf199 100644 (file)
@@ -227,6 +227,9 @@ public class DescribeCommand extends GitCommand<String> {
 
        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());