Call Git cmd_main directly
This commit is contained in:
@@ -3,10 +3,7 @@ package solutions.tretter.githugandroid
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Assume.assumeTrue
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
|
||||
class InteractiveAddEngineTest {
|
||||
@Test
|
||||
@@ -200,108 +197,4 @@ class InteractiveAddEngineTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nativeInteractiveAddSelectionUpdatesGitIndex() {
|
||||
val git = testGitBinary()
|
||||
assumeTrue(git.exists() && git.canExecute())
|
||||
val root = Files.createTempDirectory("githug-interactive-add").toFile()
|
||||
try {
|
||||
val runtime = GitRepositoryRuntime(root, git)
|
||||
val level = level(
|
||||
id = "interactive-add-test",
|
||||
title = "Interactive Add Test",
|
||||
description = "",
|
||||
hints = emptyList(),
|
||||
commandSuggestions = emptyList(),
|
||||
setup = { RepoState(initialized = true, files = listOf(GitFile("README")), branches = mapOf("master" to 0)) },
|
||||
validator = { _, _ -> false },
|
||||
)
|
||||
val repo = runtime.prepareLevel(level)
|
||||
val (menuRepo, _) = runtime.execute(level, repo, "git stage -i")
|
||||
val (updateRepo, _) = runtime.execute(level, menuRepo, "2")
|
||||
val (selectedRepo, _) = runtime.execute(level, updateRepo, "1")
|
||||
val (quitRepo, _) = runtime.execute(level, selectedRepo, "7")
|
||||
val (_, statusOutput) = runtime.execute(level, quitRepo, "git status")
|
||||
|
||||
assertTrue(selectedRepo.files.single { it.name == "README" }.staged)
|
||||
assertTrue(quitRepo.interactiveAddSession == null)
|
||||
assertTrue(statusOutput.any { it.contains("new file:") && it.contains("README") })
|
||||
} finally {
|
||||
root.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nativePatchAddSelectionUpdatesGitIndex() {
|
||||
val git = testGitBinary()
|
||||
assumeTrue(git.exists() && git.canExecute())
|
||||
val root = Files.createTempDirectory("githug-patch-add").toFile()
|
||||
try {
|
||||
val runtime = GitRepositoryRuntime(root, git)
|
||||
val level = level(
|
||||
id = "patch-add-test",
|
||||
title = "Patch Add Test",
|
||||
description = "",
|
||||
hints = emptyList(),
|
||||
commandSuggestions = emptyList(),
|
||||
setup = { RepoState(initialized = true, files = listOf(GitFile("README")), branches = mapOf("master" to 0)) },
|
||||
validator = { _, _ -> false },
|
||||
)
|
||||
val repo = runtime.prepareLevel(level)
|
||||
val (patchRepo, patchOutput) = runtime.execute(level, repo, "git add -p README")
|
||||
val (selectedRepo, _) = runtime.execute(level, patchRepo, "y")
|
||||
|
||||
assertTrue(patchOutput.any { it.contains("Stage this hunk") })
|
||||
assertTrue(selectedRepo.files.single { it.name == "README" }.staged)
|
||||
} finally {
|
||||
root.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nativePatchHunkEditorSaveUpdatesGitIndex() {
|
||||
val git = testGitBinary()
|
||||
assumeTrue(git.exists() && git.canExecute())
|
||||
val root = Files.createTempDirectory("githug-patch-edit").toFile()
|
||||
try {
|
||||
val runtime = GitRepositoryRuntime(root, git)
|
||||
val level = level(
|
||||
id = "patch-edit-test",
|
||||
title = "Patch Edit Test",
|
||||
description = "",
|
||||
hints = emptyList(),
|
||||
commandSuggestions = emptyList(),
|
||||
setup = { RepoState(initialized = true, files = listOf(GitFile("README")), branches = mapOf("master" to 0)) },
|
||||
validator = { _, _ -> false },
|
||||
)
|
||||
val repo = runtime.prepareLevel(level)
|
||||
val (patchRepo, _) = runtime.execute(level, repo, "git add -p README")
|
||||
val invocation = GitSandboxEngine.parsePatchHunkEditorInvocation(patchRepo, "e")
|
||||
?: error("Expected patch editor invocation")
|
||||
val (selectedRepo, output) = runtime.executeGitEditorCommand(level, patchRepo, invocation, invocation.initialContent)
|
||||
|
||||
assertTrue(output.any { it.contains("Applied edited hunk.") })
|
||||
assertTrue(selectedRepo.files.single { it.name == "README" }.staged)
|
||||
} finally {
|
||||
root.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
private fun testGitBinary(): File {
|
||||
System.getenv("GITHUG_TEST_GIT_BINARY")
|
||||
?.takeIf { it.isNotBlank() }
|
||||
?.let { File(it) }
|
||||
?.takeIf { it.exists() && it.canExecute() }
|
||||
?.let { return it }
|
||||
|
||||
val repoHostGit = File(repoRoot(), "build/host-git/libgit.so")
|
||||
if (repoHostGit.exists() && repoHostGit.canExecute()) return repoHostGit
|
||||
|
||||
return File("/usr/bin/git")
|
||||
}
|
||||
|
||||
private fun repoRoot(): File {
|
||||
val userDir = File(System.getProperty("user.dir") ?: ".")
|
||||
return if (File(userDir, "app/build.gradle.kts").exists()) userDir else userDir.parentFile ?: userDir
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user