Auto-commit after successful build: update app gameplay/UI, improve build setup

Changed files:\napp/build.gradle.kts
app/src/main/java/solutions/tretter/githugandroid/GitEditorCommands.kt
app/src/main/java/solutions/tretter/githugandroid/GitHugApp.kt
app/src/main/java/solutions/tretter/githugandroid/GitMessageEditorDialog.kt
app/src/main/java/solutions/tretter/githugandroid/GitRuntime.kt
app/src/test/java/solutions/tretter/githugandroid/GitEditorCommandsTest.kt
This commit is contained in:
Joe Tretter
2026-05-02 23:03:00 -05:00
parent 01d10f31c2
commit 4963123b3b
6 changed files with 313 additions and 2 deletions

View File

@@ -154,6 +154,38 @@ class GitRepositoryRuntime(private val context: Context) {
return inspectSandbox(level).copy(currentDir = currentRepo.currentDir) to listOf("Saved $path")
}
fun executeGitEditorCommand(
level: Level,
currentRepo: RepoState,
invocation: GitEditorInvocation,
message: String,
): Pair<RepoState, List<String>> {
val nativeGit = nativeGitBinary()
if (nativeGit == null) {
return GitSandboxEngine.execute(currentRepo, invocation.command.withFallbackMessage(invocation.kind, message))
}
val sandboxRoot = sandboxDir(level).canonicalFile
if (!sandboxRoot.exists()) {
prepareLevel(level)
}
val workingDir = File(sandboxRoot, currentRepo.currentDir).canonicalFile
.takeIf { it.path.startsWith(sandboxRoot.path) } ?: sandboxRoot
val messageFile = File(sandboxRoot, ".git/GITHUG_ANDROID_EDITMSG").apply {
parentFile?.mkdirs()
writeText(message)
}
val arguments = GitSandboxEngine.tokenizeCommand(invocation.command)
.drop(1)
.toMutableList()
.apply { addAll(listOf("-F", messageFile.absolutePath)) }
val result = runGit(nativeGit, workingDir, arguments)
messageFile.delete()
return inspectSandbox(level).copy(currentDir = currentRepo.currentDir) to result.outputLines
}
private fun executeHelperCommand(sandboxRoot: File, workingDir: File, currentRepo: RepoState, tokens: List<String>): Pair<RepoState, List<String>> {
return when (tokens.first()) {
"ls" -> currentRepo to workingDir.listFiles()
@@ -215,6 +247,14 @@ class GitRepositoryRuntime(private val context: Context) {
}
}
private fun String.withFallbackMessage(kind: GitEditorCommandKind, message: String): String {
val escaped = message.replace("\\", "\\\\").replace("\"", "\\\"").lineSequence().firstOrNull().orEmpty()
return when (kind) {
GitEditorCommandKind.COMMIT_MESSAGE -> "$this -m \"$escaped\""
GitEditorCommandKind.TAG_MESSAGE -> "$this -m \"$escaped\""
}
}
private fun fallbackManPage(topic: String): String {
val body = when (topic) {
"tag" -> """