Skip to content

Commit b5c4ce2

Browse files
committed
Ensure full commit id is always available
Update `GitProperties` so that the `commit.id` entry is also copied to `commit.id.full`. Prior to this commit, when returning full details, the value of `commit.id` would be replaced with a `Map` containing only `abbriv` as a key. By copying the value to a sub-key we ensure that it remains available both in the FULL and SIMPLE modes. Fixes spring-projectsgh-11892
1 parent 16b7dbf commit b5c4ce2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/GitInfoContributorTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.junit.Test;
2424

25+
import org.springframework.boot.actuate.info.InfoPropertiesInfoContributor.Mode;
2526
import org.springframework.boot.info.GitProperties;
2627

2728
import static org.assertj.core.api.Assertions.assertThat;
@@ -63,4 +64,22 @@ public void shortenCommitId() {
6364
assertThat(commit.get("id")).isEqualTo("8e29a0b");
6465
}
6566

67+
@Test
68+
@SuppressWarnings("unchecked")
69+
public void withGitIdAndAbbrev() {
70+
// gh-11892
71+
Properties properties = new Properties();
72+
properties.put("branch", "master");
73+
properties.put("commit.id", "1b3cec34f7ca0a021244452f2cae07a80497a7c7");
74+
properties.put("commit.id.abbrev", "1b3cec3");
75+
GitInfoContributor contributor = new GitInfoContributor(
76+
new GitProperties(properties), Mode.FULL);
77+
Map<String, Object> content = contributor.generateContent();
78+
Map<String, Object> commit = (Map<String, Object>) content.get("commit");
79+
assertThat(commit.get("id")).isInstanceOf(Map.class);
80+
Map<String, Object> id = (Map<String, Object>) commit.get("id");
81+
assertThat(id.get("full")).isEqualTo("1b3cec34f7ca0a021244452f2cae07a80497a7c7");
82+
assertThat(id.get("abbrev")).isEqualTo("1b3cec3");
83+
}
84+
6685
}

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/GitProperties.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ public Instant getCommitTime() {
8080
private static Properties processEntries(Properties properties) {
8181
coercePropertyToEpoch(properties, "commit.time");
8282
coercePropertyToEpoch(properties, "build.time");
83+
Object commitId = properties.get("commit.id");
84+
if (commitId != null) {
85+
// Can get converted into a map, so we copy the entry as a nested key
86+
properties.put("commit.id.full", commitId);
87+
}
8388
return properties;
8489
}
8590

0 commit comments

Comments
 (0)