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
This commit is contained in:
parent
00bb7cc9a5
commit
a2d5650b8f
|
@ -102,6 +102,8 @@ public void testDescribe() throws Exception {
|
||||||
assertEquals("alice-t1-2-g3e563c5", describe(c4, "alice*"));
|
assertEquals("alice-t1-2-g3e563c5", describe(c4, "alice*"));
|
||||||
assertEquals("bob-t2-1-g3e563c5", describe(c4, "bob*"));
|
assertEquals("bob-t2-1-g3e563c5", describe(c4, "bob*"));
|
||||||
assertEquals("bob-t2-1-g3e563c5", describe(c4, "a*", "b*", "c*"));
|
assertEquals("bob-t2-1-g3e563c5", describe(c4, "a*", "b*", "c*"));
|
||||||
|
|
||||||
|
assertEquals("bob-t2", describe(c4, false, true, 0));
|
||||||
} else {
|
} else {
|
||||||
assertEquals(null, describe(c2));
|
assertEquals(null, describe(c2));
|
||||||
assertEquals(null, describe(c3));
|
assertEquals(null, describe(c3));
|
||||||
|
|
|
@ -227,6 +227,9 @@ public DescribeCommand setAbbrev(int abbrev) {
|
||||||
|
|
||||||
private String longDescription(Ref tag, int depth, ObjectId tip)
|
private String longDescription(Ref tag, int depth, ObjectId tip)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
if (abbrev == 0) {
|
||||||
|
return formatRefName(tag.getName());
|
||||||
|
}
|
||||||
return String.format("%s-%d-g%s", formatRefName(tag.getName()), //$NON-NLS-1$
|
return String.format("%s-%d-g%s", formatRefName(tag.getName()), //$NON-NLS-1$
|
||||||
Integer.valueOf(depth),
|
Integer.valueOf(depth),
|
||||||
w.getObjectReader().abbreviate(tip, abbrev).name());
|
w.getObjectReader().abbreviate(tip, abbrev).name());
|
||||||
|
|
Loading…
Reference in New Issue