From b03362d3a40a5ba0ae554aef8ea6c612f68a26dc Mon Sep 17 00:00:00 2001 From: "Ilia.Shulgin" Date: Mon, 8 Jul 2024 10:16:00 +0200 Subject: [PATCH] [git] IJPL-157735 Add tests GitOrigin-RevId: 607383b8d97ce59b98a9510d114c1a9b1dd5b347 --- .../rebase/GitSingleRepoRebaseTest.kt | 24 +++++++++++++++++++ .../GitInteractiveRebaseUsingLogTest.kt | 23 ++++++++++++++++++ .../git4idea/tests/git4idea/test/TestGit.kt | 7 +----- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/plugins/git4idea/tests/git4idea/rebase/GitSingleRepoRebaseTest.kt b/plugins/git4idea/tests/git4idea/rebase/GitSingleRepoRebaseTest.kt index ba41ce0243bd..234bb723381e 100644 --- a/plugins/git4idea/tests/git4idea/rebase/GitSingleRepoRebaseTest.kt +++ b/plugins/git4idea/tests/git4idea/rebase/GitSingleRepoRebaseTest.kt @@ -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() diff --git a/plugins/git4idea/tests/git4idea/rebase/interactive/GitInteractiveRebaseUsingLogTest.kt b/plugins/git4idea/tests/git4idea/rebase/interactive/GitInteractiveRebaseUsingLogTest.kt index ba1ddec52edc..ed3f723502dd 100644 --- a/plugins/git4idea/tests/git4idea/rebase/interactive/GitInteractiveRebaseUsingLogTest.kt +++ b/plugins/git4idea/tests/git4idea/rebase/interactive/GitInteractiveRebaseUsingLogTest.kt @@ -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 { lateinit var entriesGeneratedUsingGit: List val editorHandler = object : GitInteractiveRebaseEditorHandler(project, repo.root) { diff --git a/plugins/git4idea/tests/git4idea/test/TestGit.kt b/plugins/git4idea/tests/git4idea/test/TestGit.kt index 4b04cb8c23b4..9b42d64135b2 100644 --- a/plugins/git4idea/tests/git4idea/test/TestGit.kt +++ b/plugins/git4idea/tests/git4idea/test/TestGit.kt @@ -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 } }