Skip to content

Commit 4762372

Browse files
committed
fix: 修复 worktree 中 grgit.head() 可能为 null 的问题
1 parent 963335e commit 4762372

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

build.gradle.kts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ allprojects {
6767
// The ".git" directory may not exist when resolving dependencies in the Docker image build
6868
if (File(rootProject.rootDir, ".git").exists()) {
6969
val grgit = org.ajoberstar.grgit.Grgit.open(mapOf("currentDir" to rootProject.rootDir))
70-
rootProject.extra["gitHashFull"] = grgit.head().id
71-
rootProject.extra["gitCommitTime"] = grgit.head().dateTime.withZoneSameLocal(java.time.ZoneOffset.UTC)
70+
val head = grgit.head()
71+
if (head != null) {
72+
rootProject.extra["gitHashFull"] = head.id
73+
rootProject.extra["gitCommitTime"] = head.dateTime.withZoneSameLocal(java.time.ZoneOffset.UTC)
74+
}
7275
grgit.close()
7376
}
7477

0 commit comments

Comments
 (0)