Fix interactive add/stage auto-update behavior
This commit is contained in:
@@ -19,8 +19,8 @@ android {
|
||||
applicationId = "solutions.tretter.githugandroid"
|
||||
minSdk = 26
|
||||
targetSdk = 35
|
||||
versionCode = 143
|
||||
versionName = "0.1.142"
|
||||
versionCode = 144
|
||||
versionName = "0.1.143"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
|
||||
@@ -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>")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -308,16 +308,30 @@ class GitSandboxEngineTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun interactiveStageUsesConsoleText() {
|
||||
fun interactiveStageShowsMenuWithoutStagingOrAutoCommands() {
|
||||
val repo = RepoState(initialized = true, files = listOf(GitFile("README")))
|
||||
|
||||
val (updatedRepo, output) = GitSandboxEngine.execute(repo, "git stage -i")
|
||||
|
||||
assertTrue(updatedRepo.files.single { it.name == "README" }.staged)
|
||||
assertFalse(updatedRepo.files.single { it.name == "README" }.staged)
|
||||
assertTrue(output.any { it.contains("What now>") })
|
||||
assertFalse(output.any { it.contains("What now> update") })
|
||||
assertFalse(output.any { it.contains("What now> quit") })
|
||||
assertFalse(output.any { it.contains("GitHug Android") })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun interactiveAddShowsMenuWithoutStagingOrAutoCommands() {
|
||||
val repo = RepoState(initialized = true, files = listOf(GitFile("README")))
|
||||
|
||||
val (updatedRepo, output) = GitSandboxEngine.execute(repo, "git add -i")
|
||||
|
||||
assertFalse(updatedRepo.files.single { it.name == "README" }.staged)
|
||||
assertTrue(output.any { it.contains("What now>") })
|
||||
assertFalse(output.any { it.contains("What now> update") })
|
||||
assertFalse(output.any { it.contains("What now> quit") })
|
||||
}
|
||||
|
||||
private fun testGitBinary(): File {
|
||||
System.getenv("GITHUG_TEST_GIT_BINARY")
|
||||
?.takeIf { it.isNotBlank() }
|
||||
|
||||
Reference in New Issue
Block a user