Search in sources :

Example 1 with GitFileHistoryProvider

use of org.eclipse.egit.core.internal.storage.GitFileHistoryProvider in project egit by eclipse.

the class GitBlobStorageTest method testGitFileHistorySingleProjectOk.

@Test
public void testGitFileHistorySingleProjectOk() throws Exception {
    IProgressMonitor progress = new NullProgressMonitor();
    TestProject singleRepoProject = new TestProject(true, "Project-2");
    IProject proj = singleRepoProject.getProject();
    File singleProjectGitDir = new File(proj.getLocation().toFile(), Constants.DOT_GIT);
    if (singleProjectGitDir.exists())
        FileUtils.delete(singleProjectGitDir, FileUtils.RECURSIVE | FileUtils.RETRY);
    Repository singleProjectRepo = FileRepositoryBuilder.create(singleProjectGitDir);
    singleProjectRepo.create();
    // Repository must be mapped in order to test the GitFileHistory
    Activator.getDefault().getRepositoryUtil().addConfiguredRepository(singleProjectGitDir);
    ConnectProviderOperation connectOp = new ConnectProviderOperation(proj, singleProjectGitDir);
    connectOp.execute(progress);
    try (Git git = new Git(singleProjectRepo)) {
        IFile file = proj.getFile("file");
        file.create(new ByteArrayInputStream("data".getBytes("UTF-8")), 0, progress);
        git.add().addFilepattern(".").call();
        RevCommit commit = git.commit().setAuthor("JUnit", "junit@jgit.org").setAll(true).setMessage("First commit").call();
        GitFileHistoryProvider fhProvider = new GitFileHistoryProvider();
        IFileHistory fh = fhProvider.getFileHistoryFor(singleRepoProject.getProject(), 0, null);
        assertNotNull(fh);
        assertEquals(fh.getFileRevisions().length, 1);
        assertNotNull(fh.getFileRevision(commit.getId().getName()));
    } finally {
        DisconnectProviderOperation disconnectOp = new DisconnectProviderOperation(Collections.singletonList(proj));
        disconnectOp.execute(progress);
        Activator.getDefault().getRepositoryUtil().removeDir(singleProjectGitDir);
        singleProjectRepo.close();
        singleRepoProject.dispose();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IProject(org.eclipse.core.resources.IProject) IFileHistory(org.eclipse.team.core.history.IFileHistory) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) TestProject(org.eclipse.egit.core.test.TestProject) ByteArrayInputStream(java.io.ByteArrayInputStream) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IFile(org.eclipse.core.resources.IFile) File(java.io.File) DisconnectProviderOperation(org.eclipse.egit.core.op.DisconnectProviderOperation) RevCommit(org.eclipse.jgit.revwalk.RevCommit) GitFileHistoryProvider(org.eclipse.egit.core.internal.storage.GitFileHistoryProvider) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 GitFileHistoryProvider (org.eclipse.egit.core.internal.storage.GitFileHistoryProvider)1 ConnectProviderOperation (org.eclipse.egit.core.op.ConnectProviderOperation)1 DisconnectProviderOperation (org.eclipse.egit.core.op.DisconnectProviderOperation)1 TestProject (org.eclipse.egit.core.test.TestProject)1 Git (org.eclipse.jgit.api.Git)1 Repository (org.eclipse.jgit.lib.Repository)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 IFileHistory (org.eclipse.team.core.history.IFileHistory)1 Test (org.junit.Test)1