Polish "Use git.commit.id.abbrev if present" contribution

Closes gh-8781
pull/8785/merge
Stephane Nicoll 8 years ago
parent 30b6166bc1
commit 52527c7298

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -54,11 +54,10 @@ public class GitProperties extends InfoProperties {
* @return the short commit id
*/
public String getShortCommitId() {
String idAbbrev = get("commit.id.abbrev");
if (idAbbrev != null) {
return idAbbrev;
String shortId = get("commit.id.abbrev");
if (shortId != null) {
return shortId;
}
String id = getCommitId();
if (id == null) {
return null;

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -73,6 +73,14 @@ public class GitPropertiesTests {
assertThat(properties.get("commit.time")).isEqualTo("2016-03-04 15:22:24");
}
@Test
public void shortCommitUsedIfPresent() {
GitProperties properties = new GitProperties(
createProperties("master", "abcdefghijklmno", "abcdefgh", "1457527123"));
assertThat(properties.getCommitId()).isEqualTo("abcdefghijklmno");
assertThat(properties.getShortCommitId()).isEqualTo("abcdefgh");
}
@Test
public void shortenCommitIdShorterThan7() {
GitProperties properties = new GitProperties(
@ -89,14 +97,6 @@ public class GitPropertiesTests {
assertThat(properties.getShortCommitId()).isEqualTo("abcdefg");
}
@Test
public void shortCommitIdCustomLength() {
GitProperties properties = new GitProperties(
createProperties("master", "abcdefghijklmno", "abcdefgh", "1457527123"));
assertThat(properties.getCommitId()).isEqualTo("abcdefghijklmno");
assertThat(properties.getShortCommitId()).isEqualTo("abcdefgh");
}
private static Properties createProperties(String branch, String commitId,
String commitIdAbbrev, String commitTime) {
Properties properties = new Properties();

Loading…
Cancel
Save