Commit 52527c72 authored by Stephane Nicoll's avatar Stephane Nicoll

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

Closes gh-8781
parent 30b6166b
/*
* 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;
......
/*
* 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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment