diff --git a/plugins/git4idea/src/git4idea/history/GitFileHistory.kt b/plugins/git4idea/src/git4idea/history/GitFileHistory.kt index 78ae7b5dafc1..e8d4a85af105 100644 --- a/plugins/git4idea/src/git4idea/history/GitFileHistory.kt +++ b/plugins/git4idea/src/git4idea/history/GitFileHistory.kt @@ -26,6 +26,7 @@ import git4idea.history.GitLogParser.GitLogOption import git4idea.log.GitLogProvider import git4idea.repo.GitRepositoryManager import org.jetbrains.annotations.NonNls +import org.jetbrains.annotations.TestOnly import java.util.* import java.util.function.Consumer @@ -87,6 +88,9 @@ class GitFileHistory internal constructor(private val project: Project, } } + @TestOnly + internal fun getFilePath() = path + @Throws(VcsException::class) private fun runGitLog(logParser: GitLogParser, startPath: FilePath, diff --git a/plugins/git4idea/tests/git4idea/history/GitFileHistoryTest.kt b/plugins/git4idea/tests/git4idea/history/GitFileHistoryTest.kt index 5bf31a7bd842..f8aca17517d8 100644 --- a/plugins/git4idea/tests/git4idea/history/GitFileHistoryTest.kt +++ b/plugins/git4idea/tests/git4idea/history/GitFileHistoryTest.kt @@ -6,6 +6,7 @@ import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.vcs.Executor.* import com.intellij.openapi.vcs.VcsException import com.intellij.openapi.vcs.changes.ChangeListManagerImpl +import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager import com.intellij.openapi.vcs.history.VcsFileRevision import com.intellij.openapi.vfs.VirtualFile import com.intellij.util.CollectConsumer @@ -82,7 +83,7 @@ class GitFileHistoryTest : GitSingleRepoTest() { val file = commits.first().file val history = collectFileHistory(file) - assertSameHistory(commits, history, "History is different for file${file.relativePath()}.") + assertSameHistory(commits, history, file) } @Throws(VcsException::class, IOException::class) @@ -317,9 +318,9 @@ class GitFileHistoryTest : GitSingleRepoTest() { val monorepoMergeFile2 = TestCommit(monorepoMerge, monorepoMergeMessage, repo.root, repo2MovedFile) assertSameHistory((commits + monorepoMergeFile1).sortedBy { it.hash }, - collectFileHistory(repo1MovedFile, full = true).sortedBy { it.revisionNumber.asString() }) + collectFileHistory(repo1MovedFile, full = true).sortedBy { it.revisionNumber.asString() }, repo1MovedFile) assertSameHistory((commits + monorepoMergeFile2).sortedBy { it.hash }, - collectFileHistory(repo2MovedFile, full = true).sortedBy { it.revisionNumber.asString() }) + collectFileHistory(repo2MovedFile, full = true).sortedBy { it.revisionNumber.asString() }, repo2MovedFile) } @Throws(VcsException::class, IOException::class) @@ -382,16 +383,20 @@ class GitFileHistoryTest : GitSingleRepoTest() { } private fun collectFileHistory(file: File, startingRevisions: List, full: Boolean): List { + VcsDirtyScopeManager.getInstance(project).markEverythingDirty() ChangeListManagerImpl.getInstanceImpl(project).waitEverythingDoneInTestMode() val path = VcsUtil.getFilePath(file, false) + val gitFileHistory = GitFileHistory(myProject, repo.root, path, startingRevisions, full) + TestCase.assertEquals("Last commit path differs from the requested one", path, gitFileHistory.getFilePath()) return buildList { - GitFileHistory(myProject, repo.root, path, startingRevisions, full).load(::add) + gitFileHistory.load(::add) } } - private fun assertSameHistory(expected: List, actual: List, message: String = "History is different.") { - TestCase.assertEquals(message, expected, actual.map { it.toTestCommit() }) + private fun assertSameHistory(expected: List, actual: List, file: File? = null) { + val description = if (file == null) "History is different." else "History for ${file.relativePath()} is different." + TestCase.assertEquals(description, expected, actual.map { it.toTestCommit() }) } private data class TestCommit(val hash: String, val commitMessage: String, val root: VirtualFile, val file: File) {