diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/GitInfoContributorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/GitInfoContributorTests.java index 34cc836078..1bc29c7079 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/GitInfoContributorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/GitInfoContributorTests.java @@ -22,6 +22,7 @@ import java.util.Properties; import org.junit.Test; +import org.springframework.boot.actuate.info.InfoPropertiesInfoContributor.Mode; import org.springframework.boot.info.GitProperties; import static org.assertj.core.api.Assertions.assertThat; @@ -63,4 +64,22 @@ public class GitInfoContributorTests { assertThat(commit.get("id")).isEqualTo("8e29a0b"); } + @Test + @SuppressWarnings("unchecked") + public void withGitIdAndAbbrev() { + // gh-11892 + Properties properties = new Properties(); + properties.put("branch", "master"); + properties.put("commit.id", "1b3cec34f7ca0a021244452f2cae07a80497a7c7"); + properties.put("commit.id.abbrev", "1b3cec3"); + GitInfoContributor contributor = new GitInfoContributor( + new GitProperties(properties), Mode.FULL); + Map content = contributor.generateContent(); + Map commit = (Map) content.get("commit"); + assertThat(commit.get("id")).isInstanceOf(Map.class); + Map id = (Map) commit.get("id"); + assertThat(id.get("full")).isEqualTo("1b3cec34f7ca0a021244452f2cae07a80497a7c7"); + assertThat(id.get("abbrev")).isEqualTo("1b3cec3"); + } + } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/GitProperties.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/GitProperties.java index 066f8241ae..ffb7eb1a58 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/GitProperties.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/GitProperties.java @@ -80,6 +80,11 @@ public class GitProperties extends InfoProperties { private static Properties processEntries(Properties properties) { coercePropertyToEpoch(properties, "commit.time"); coercePropertyToEpoch(properties, "build.time"); + Object commitId = properties.get("commit.id"); + if (commitId != null) { + // Can get converted into a map, so we copy the entry as a nested key + properties.put("commit.id.full", commitId); + } return properties; }