mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-10-06 03:38:23 +00:00
fix(amethyst): set git cwd in versionName branch detection so worktrees work
ProcessBuilder("git", …) inherited the daemon's working directory, which
in a git worktree (or when the Gradle daemon was started elsewhere) is
not the project root. git printed "fatal: not a git repository"; with
redirectErrorStream that landed in stdout, got cleaned to dashes, and
truncated to exactly "fatal--not-a-git-rep" — visible as the version
suffix in installed builds.
Pass rootDir to ProcessBuilder.directory() so git always runs at the
worktree root, and check the exit code so any future failure falls back
to "unknown" instead of leaking stderr into the version name.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
b6361f133c
commit
908eedb831
@@ -8,10 +8,11 @@ plugins {
|
||||
alias(libs.plugins.googleKsp)
|
||||
}
|
||||
|
||||
fun getCurrentBranch(): String =
|
||||
fun getCurrentBranch(workingDir: java.io.File): String =
|
||||
try {
|
||||
val process =
|
||||
ProcessBuilder("git", "rev-parse", "--abbrev-ref", "HEAD")
|
||||
.directory(workingDir)
|
||||
.redirectErrorStream(true)
|
||||
.start()
|
||||
val branch =
|
||||
@@ -19,15 +20,18 @@ fun getCurrentBranch(): String =
|
||||
.bufferedReader()
|
||||
.use { it.readText() }
|
||||
.trim()
|
||||
process.waitFor()
|
||||
branch
|
||||
val exitCode = process.waitFor()
|
||||
if (exitCode != 0) "unknown" else branch
|
||||
} catch (e: Exception) {
|
||||
println("Could not determine git branch: ${e.message}")
|
||||
"unknown"
|
||||
}
|
||||
|
||||
fun generateVersionName(baseVersion: String): String {
|
||||
val currentBranch = getCurrentBranch()
|
||||
fun generateVersionName(
|
||||
baseVersion: String,
|
||||
workingDir: java.io.File,
|
||||
): String {
|
||||
val currentBranch = getCurrentBranch(workingDir)
|
||||
|
||||
if (currentBranch == "main" || currentBranch == "master" || currentBranch == "unknown" || currentBranch == "HEAD") {
|
||||
return baseVersion
|
||||
@@ -73,7 +77,7 @@ android {
|
||||
.get()
|
||||
.toInt()
|
||||
versionCode = 447
|
||||
versionName = generateVersionName(libs.versions.app.get())
|
||||
versionName = generateVersionName(libs.versions.app.get(), rootDir)
|
||||
buildConfigField("String", "RELEASE_NOTES_ID", "\"8ec0d94550b5538115226c6858159b1115713c9c6ed942173bd4fd5d292d8ba6\"")
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
Reference in New Issue
Block a user