Open app editor for interactive rebase todo
This commit is contained in:
@@ -23,6 +23,19 @@ class GitEditorCommandsTest {
|
||||
assertNull(parseGitEditorInvocation("git commit --amend --no-edit"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun interactiveRebaseOpensTodoEditor() {
|
||||
val invocation = parseGitEditorInvocation("git rebase -i HEAD~3")
|
||||
|
||||
assertEquals(GitEditorCommandKind.REBASE_TODO, invocation?.kind)
|
||||
assertEquals("Edit Rebase Todo", invocation?.title)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun bareInteractiveRebaseDoesNotOpenTodoEditor() {
|
||||
assertNull(parseGitEditorInvocation("git rebase -i"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun annotatedTagWithoutMessageOpensEditor() {
|
||||
val invocation = parseGitEditorInvocation("git tag -a v1.0")
|
||||
|
||||
@@ -382,6 +382,35 @@ class GitSandboxEngineTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nativeInteractiveRebaseUsesAppSequenceEditorContent() {
|
||||
val git = testGitBinary()
|
||||
assumeTrue(git.exists() && git.canExecute())
|
||||
val root = Files.createTempDirectory("githug-interactive-rebase-editor").toFile()
|
||||
try {
|
||||
val runtime = GitRepositoryRuntime(root, git)
|
||||
val level = reorderLevel()
|
||||
val repo = runtime.prepareLevel(level)
|
||||
val invocation = parseGitEditorInvocation("git rebase -i HEAD~3")
|
||||
?: error("Expected interactive rebase editor invocation")
|
||||
val todo = runtime.gitEditorInitialContent(level, repo, invocation)
|
||||
val reorderedTodo = todo.lines().toMutableList().also { lines ->
|
||||
val secondPick = lines.indexOfFirst { it.contains("Third commit") }
|
||||
val thirdPick = lines.indexOfFirst { it.contains("Second commit") }
|
||||
val thirdLine = lines[thirdPick]
|
||||
lines[thirdPick] = lines[secondPick]
|
||||
lines[secondPick] = thirdLine
|
||||
}.joinToString("\n")
|
||||
|
||||
val (updatedRepo, output) = runtime.executeGitEditorCommand(level, repo, invocation, reorderedTodo)
|
||||
|
||||
assertFalse(output.any { it.contains("Terminal is dumb", ignoreCase = true) })
|
||||
assertTrue(level.validator(updatedRepo, invocation.command))
|
||||
} finally {
|
||||
root.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
private fun testGitBinary(): File {
|
||||
System.getenv("GITHUG_TEST_GIT_BINARY")
|
||||
?.takeIf { it.isNotBlank() }
|
||||
|
||||
Reference in New Issue
Block a user