From 67a7352c672d054b9e6cd0e996a4fa92ba0c237e Mon Sep 17 00:00:00 2001 From: "Lukas Rieger (Blue)" Date: Sat, 7 Dec 2024 12:54:15 +0100 Subject: [PATCH] Add falback if branch command fails --- buildSrc/src/main/kotlin/versioning.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/kotlin/versioning.kt b/buildSrc/src/main/kotlin/versioning.kt index b5ba46c..1fd19b0 100644 --- a/buildSrc/src/main/kotlin/versioning.kt +++ b/buildSrc/src/main/kotlin/versioning.kt @@ -15,7 +15,7 @@ fun Project.gitVersion(): String { val lastTag = if (runCommand("git tag", "").isEmpty()) "" else runCommand("git describe --tags --abbrev=0", "") val lastVersion = if (lastTag.isEmpty()) "0.0" else lastTag.substring(1) // remove the leading 'v' val commits = runCommand("git rev-list --count $lastTag..HEAD", "0") - val branch = runCommand("git branch --show-current") + val branch = runCommand("git branch --show-current", "master") val gitVersion = lastVersion + (if (branch == "master") "" else "-${branch.replace('/', '.')}") + (if (commits == "0") "" else "-$commits") +