[git] IJPL-157735 Add tests

GitOrigin-RevId: 607383b8d97ce59b98a9510d114c1a9b1dd5b347
This commit is contained in:
Ilia.Shulgin
2024-07-08 10:16:00 +02:00
committed by intellij-monorepo-bot
parent 759bbb8da1
commit b03362d3a4
3 changed files with 48 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ import com.intellij.openapi.ui.Messages
import com.intellij.openapi.vcs.Executor
import com.intellij.openapi.vcs.Executor.overwrite
import com.intellij.openapi.vcs.Executor.touch
import com.intellij.openapi.vcs.VcsException
import com.intellij.openapi.vcs.ui.CommitMessage
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.VfsUtil
@@ -709,6 +710,29 @@ class GitSingleRepoRebaseTest : GitRebaseBaseTest() {
}
}
// IJPL-156329
// We are not expecting "error: there was a problem with the editor ..." in "Rebase failed" pop-up
fun `test VcsException is handled without showing native git editor error`() {
build {
0()
1()
2()
}
refresh()
updateChangeListManager()
dialogManager.onDialog(GitInteractiveRebaseDialog::class.java) {
DialogWrapper.OK_EXIT_CODE
}
val errorMessage = "test exception message!!!"
git.setInteractiveRebaseEditor(TestGitImpl.InteractiveRebaseEditor({ throw VcsException(errorMessage) }, null))
rebaseInteractively()
assertErrorNotification("Rebase failed", errorMessage)
}
private fun checkCheckoutAndRebase(expectedNotification: () -> String) {
repo.git("checkout master")
refresh()

View File

@@ -2,14 +2,17 @@
package git4idea.rebase.interactive
import com.intellij.openapi.progress.EmptyProgressIndicator
import com.intellij.openapi.ui.DialogWrapper
import com.intellij.vcs.log.VcsCommitMetadata
import com.intellij.vcs.log.data.VcsLogData
import git4idea.branch.GitRebaseParams
import git4idea.i18n.GitBundle
import git4idea.log.createLogData
import git4idea.log.refreshAndWait
import git4idea.rebase.GitInteractiveRebaseEditorHandler
import git4idea.rebase.GitRebaseEntry
import git4idea.rebase.GitRebaseUtils
import git4idea.rebase.interactive.dialog.GitInteractiveRebaseDialog
import git4idea.test.GitSingleRepoTest
class GitInteractiveRebaseUsingLogTest : GitSingleRepoTest() {
@@ -112,6 +115,26 @@ class GitInteractiveRebaseUsingLogTest : GitSingleRepoTest() {
}
}
// IJPL-156329
fun `test incorrect git-rebase-todo file was generated`() {
val commit = file("firstFile.txt").create("").addCommit("0").details()
build {
1()
2()
}
logData.refreshAndWait(repo, true)
updateChangeListManager()
dialogManager.onDialog(GitInteractiveRebaseDialog::class.java) {
git("reset HEAD~ --hard")
DialogWrapper.OK_EXIT_CODE
}
interactivelyRebaseUsingLog(repo, commit, logData)
assertErrorNotification("Rebase failed", GitBundle.message("rebase.using.log.couldnt.start.error"))
}
private fun getRebaseEntriesUsingGit(commit: VcsCommitMetadata): List<GitRebaseEntry> {
lateinit var entriesGeneratedUsingGit: List<GitRebaseEntry>
val editorHandler = object : GitInteractiveRebaseEditorHandler(project, repo.root) {

View File

@@ -102,12 +102,7 @@ class TestGitImpl : GitImpl() {
}
private fun handleEditor(file: File, editor: (String) -> String): Boolean {
try {
FileUtil.writeToFile(file, editor(FileUtil.loadFile(file)))
}
catch (e: Exception) {
LOG.error(e)
}
FileUtil.writeToFile(file, editor(FileUtil.loadFile(file)))
return true
}
}