Fix interactive add/stage auto-update behavior
This commit is contained in:
@@ -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>")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user