From 52527c7298e20d499f622c894675d92181cebd84 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 31 Mar 2017 15:09:24 +0200 Subject: [PATCH] Polish "Use git.commit.id.abbrev if present" contribution Closes gh-8781 --- .../boot/info/GitProperties.java | 9 ++++----- .../boot/info/GitPropertiesTests.java | 18 +++++++++--------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/info/GitProperties.java b/spring-boot/src/main/java/org/springframework/boot/info/GitProperties.java index bd5ca6d684..64b7f73e49 100644 --- a/spring-boot/src/main/java/org/springframework/boot/info/GitProperties.java +++ b/spring-boot/src/main/java/org/springframework/boot/info/GitProperties.java @@ -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; diff --git a/spring-boot/src/test/java/org/springframework/boot/info/GitPropertiesTests.java b/spring-boot/src/test/java/org/springframework/boot/info/GitPropertiesTests.java index bf8555de5f..0b7a8f7cde 100644 --- a/spring-boot/src/test/java/org/springframework/boot/info/GitPropertiesTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/info/GitPropertiesTests.java @@ -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();