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/EditorCommands.kt
app/src/main/java/solutions/tretter/githugandroid/GitHugApp.kt
app/src/main/java/solutions/tretter/githugandroid/GitRuntime.kt
app/src/main/java/solutions/tretter/githugandroid/TextEditorDialog.kt
app/src/test/java/solutions/tretter/githugandroid/EditorCommandsTest.kt
This commit is contained in:
Joe Tretter
2026-05-02 21:50:34 -05:00
parent d6c4c4a2df
commit 17f19ca0ba
6 changed files with 327 additions and 42 deletions

View File

@@ -84,9 +84,59 @@ class GitRepositoryRuntime(private val context: Context) {
add(" binary path: nativeLibraryDir/libgit.so")
add(" selected ABI: ${Build.SUPPORTED_ABIS.firstOrNull() ?: "unknown"}")
add(" helper commands: ls, pwd, cat, touch, mkdir, rm, echo")
add(" visual editors: vi, nano, emacs, ed, ex")
}
}
fun readEditorFile(level: Level, currentRepo: RepoState, path: String): Pair<String, List<String>> {
val nativeGit = nativeGitBinary()
if (nativeGit == null) {
return currentRepo.files.find { it.name == path }?.content.orEmpty() to emptyList()
}
val sandboxRoot = sandboxDir(level).canonicalFile
val workingDir = File(sandboxRoot, currentRepo.currentDir).canonicalFile
.takeIf { it.path.startsWith(sandboxRoot.path) } ?: sandboxRoot
val file = File(workingDir, path).canonicalFile
if (!file.path.startsWith(sandboxRoot.path)) {
return "" to listOf("editor: $path: Permission denied")
}
if (file.exists() && file.isDirectory) {
return "" to listOf("editor: $path: Is a directory")
}
return if (file.exists()) file.readText() to emptyList() else "" to emptyList()
}
fun writeEditorFile(level: Level, currentRepo: RepoState, path: String, content: String): Pair<RepoState, List<String>> {
val nativeGit = nativeGitBinary()
if (nativeGit == null) {
val updatedFiles = currentRepo.files.toMutableList()
val index = updatedFiles.indexOfFirst { it.name == path }
if (index == -1) {
updatedFiles += GitFile(name = path, content = content)
} else {
updatedFiles[index] = updatedFiles[index].copy(content = content)
}
return currentRepo.copy(files = updatedFiles) to listOf("Saved $path")
}
val sandboxRoot = sandboxDir(level).canonicalFile
val workingDir = File(sandboxRoot, currentRepo.currentDir).canonicalFile
.takeIf { it.path.startsWith(sandboxRoot.path) } ?: sandboxRoot
val file = File(workingDir, path).canonicalFile
if (!file.path.startsWith(sandboxRoot.path)) {
return currentRepo to listOf("editor: $path: Permission denied")
}
if (file.exists() && file.isDirectory) {
return currentRepo to listOf("editor: $path: Is a directory")
}
file.parentFile?.mkdirs()
file.writeText(content)
return inspectSandbox(level).copy(currentDir = currentRepo.currentDir) to listOf("Saved $path")
}
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()