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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -54,11 +54,10 @@ public class GitProperties extends InfoProperties { ...@@ -54,11 +54,10 @@ public class GitProperties extends InfoProperties {
* @return the short commit id * @return the short commit id
*/ */
public String getShortCommitId() { public String getShortCommitId() {
String idAbbrev = get("commit.id.abbrev"); String shortId = get("commit.id.abbrev");
if (idAbbrev != null) { if (shortId != null) {
return idAbbrev; return shortId;
} }
String id = getCommitId(); String id = getCommitId();
if (id == null) { if (id == null) {
return 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -73,6 +73,14 @@ public class GitPropertiesTests { ...@@ -73,6 +73,14 @@ public class GitPropertiesTests {
assertThat(properties.get("commit.time")).isEqualTo("2016-03-04 15:22:24"); 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 @Test
public void shortenCommitIdShorterThan7() { public void shortenCommitIdShorterThan7() {
GitProperties properties = new GitProperties( GitProperties properties = new GitProperties(
...@@ -89,14 +97,6 @@ public class GitPropertiesTests { ...@@ -89,14 +97,6 @@ public class GitPropertiesTests {
assertThat(properties.getShortCommitId()).isEqualTo("abcdefg"); 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, private static Properties createProperties(String branch, String commitId,
String commitIdAbbrev, String commitTime) { String commitIdAbbrev, String commitTime) {
Properties properties = new Properties(); 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