summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorSebastian Schuberth <sebastian.schuberth@bosch.io>2022-01-05 18:07:48 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2022-02-19 22:04:28 +0100
commita7386ffe3aada6d1e0f73536f985dbe21cebadc2 (patch)
tree46f0e2b12a3e0177fc8eb8946a4a47a363343470 /org.eclipse.jgit.test/tst
parent69ef598bd933dda36ff852700e5ff7853e7ae04e (diff)
downloadjgit-a7386ffe3aada6d1e0f73536f985dbe21cebadc2.tar.gz
jgit-a7386ffe3aada6d1e0f73536f985dbe21cebadc2.zip
DescribeCommand: Support configuring the hash abbreviation
Bug: 537883 Signed-off-by: Sebastian Schuberth <sebastian.schuberth@bosch.io> Change-Id: Ic52dcebc564bbb0d934cc3a6205704b7aeaee30e
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java28
1 files changed, 25 insertions, 3 deletions
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 b460e3f52e..2051169996 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
@@ -10,9 +10,11 @@
package org.eclipse.jgit.api;
import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.OBJECT_ID_ABBREV_STRING_LENGTH;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import java.io.BufferedWriter;
@@ -108,6 +110,21 @@ public class DescribeCommandTest extends RepositoryTestCase {
assertEquals("3747db3", describe(c2, false, true));
assertEquals("44579eb", describe(c3, false, true));
assertEquals("3e563c5", describe(c4, false, true));
+
+ assertEquals("3747db3267", describe(c2, false, true, 10));
+ assertEquals("44579ebe7f", describe(c3, false, true, 10));
+ assertEquals("3e563c5592", describe(c4, false, true, 10));
+
+ assertEquals("3e", describe(c4, false, true, 2));
+ assertEquals("3e563c55927905f21e3bc7c00a3d83a31bf4ed3a",
+ describe(c4, false, true, 40));
+
+ assertThrows(StringIndexOutOfBoundsException.class,
+ () -> describe(c4, false, true, -10));
+ assertThrows(StringIndexOutOfBoundsException.class,
+ () -> describe(c4, false, true, 1));
+ assertThrows(StringIndexOutOfBoundsException.class,
+ () -> describe(c4, false, true, 41));
}
// test default target
@@ -474,10 +491,15 @@ public class DescribeCommandTest extends RepositoryTestCase {
}
}
+ private String describe(ObjectId c1, boolean longDesc, boolean always,
+ int abbrev) throws GitAPIException, IOException {
+ return git.describe().setTarget(c1).setTags(describeUseAllTags)
+ .setLong(longDesc).setAlways(always).setAbbrev(abbrev).call();
+ }
+
private String describe(ObjectId c1, boolean longDesc, boolean always)
throws GitAPIException, IOException {
- return git.describe().setTarget(c1).setTags(describeUseAllTags)
- .setLong(longDesc).setAlways(always).call();
+ return describe(c1, longDesc, always, OBJECT_ID_ABBREV_STRING_LENGTH);
}
private String describe(ObjectId c1) throws GitAPIException, IOException {