Fix interactive add/stage auto-update behavior

This commit is contained in:
Joe Tretter
2026-05-13 19:03:12 -05:00
parent 618e6e36bd
commit 482483deed
3 changed files with 21 additions and 24 deletions

View File

@@ -174,23 +174,10 @@ object GitSandboxEngine {
val candidates = repo.files.filter { file ->
!file.deleted && (target == null || target == "." || file.name == target || file.name.startsWith(target.trimEnd('/') + "/"))
}
val updated = repo.files.map { file ->
if (file.deleted) {
file
} else if (target == null || target == "." || file.name == target || file.name.startsWith(target.trimEnd('/') + "/")) {
file.copy(staged = true)
} else {
file
}
}
val stagedCount = updated.count { updatedFile ->
val before = repo.files.firstOrNull { it.name == updatedFile.name }
updatedFile.staged && before?.staged != true
}
return repo.copy(files = updated) to interactiveAddConsoleLines(candidates, target, stagedCount)
return repo to interactiveAddConsoleLines(candidates)
}
private fun interactiveAddConsoleLines(candidates: List<GitFile>, target: String?, stagedCount: Int): List<String> {
private fun interactiveAddConsoleLines(candidates: List<GitFile>): List<String> {
return buildList {
add(" staged unstaged path")
candidates.forEachIndexed { index, file ->
@@ -207,11 +194,7 @@ object GitSandboxEngine {
add("*** Commands ***")
add(" 1: status 2: update 3: revert 4: add untracked")
add(" 5: patch 6: diff 7: quit 8: help")
add("What now> update")
add("Update>> ${target ?: "*"}")
add("updated ${if (target == null || target == ".") "$stagedCount path(s)" else target}")
add("What now> quit")
add("Bye.")
add("What now>")
}
}