Search in sources :

Example 6 with IFileHistory

use of org.eclipse.team.core.history.IFileHistory in project egit by eclipse.

the class HistoryTest method querySingleRevisions.

@Test
public void querySingleRevisions() throws CoreException {
    for (RevCommit commit : commits) {
        for (IFile target : Arrays.asList(iFile1, iFile2)) {
            testRepository.checkoutBranch(commit.getName());
            final IFileHistory history = historyProvider.getFileHistoryFor(target, IFileHistoryProvider.SINGLE_REVISION, new NullProgressMonitor());
            assertNotNull(history);
            final IFileRevision[] revisions = history.getFileRevisions();
            assertEquals(1, revisions.length);
            assertRevisionMatchCommit(revisions[0], commit);
        }
    }
}
Also used : IFileHistory(org.eclipse.team.core.history.IFileHistory) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IFileRevision(org.eclipse.team.core.history.IFileRevision) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 7 with IFileHistory

use of org.eclipse.team.core.history.IFileHistory 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)

Example 8 with IFileHistory

use of org.eclipse.team.core.history.IFileHistory in project egit by eclipse.

the class HistoryTest method queryFile1Targets.

@Test
public void queryFile1Targets() {
    final IFileHistory history = historyProvider.getFileHistoryFor(iFile1, IFileHistoryProvider.NONE, new NullProgressMonitor());
    assertNotNull(history);
    final IFileRevision[] revisions = history.getFileRevisions();
    IFileRevision branchFileRevision1 = null;
    IFileRevision masterFileRevision3 = null;
    IFileRevision masterFileRevision1 = null;
    for (IFileRevision revision : revisions) {
        final String revisionId = revision.getContentIdentifier();
        if (branchCommit1.getName().equals(revisionId))
            branchFileRevision1 = revision;
        else if (masterCommit3.getName().equals(revisionId))
            masterFileRevision3 = revision;
        else if (masterCommit1.getName().equals(revisionId))
            masterFileRevision1 = revision;
    }
    assertNotNull(branchFileRevision1);
    assertNotNull(masterFileRevision3);
    assertNotNull(masterFileRevision1);
    /*
		 * The "direct" child of masterCommit1 is masterCommit2. However, that
		 * commit did not contain file1. We thus expect the returned children to
		 * be masterCommit3 and branchCommit1, since the ignored masterCommit2
		 * is a branching point.
		 */
    final IFileRevision[] masterCommit1Children = history.getTargets(masterFileRevision1);
    assertEquals(2, masterCommit1Children.length);
    final List<RevCommit> expected = new ArrayList<RevCommit>(Arrays.asList(masterCommit3, branchCommit1));
    assertMatchingRevisions(Arrays.asList(masterCommit1Children), expected);
    // masterCommit3 and branchCommit1 are leafs
    final IFileRevision[] masterCommit3Children = history.getTargets(masterFileRevision3);
    assertEquals(0, masterCommit3Children.length);
    final IFileRevision[] branchCommit1Children = history.getTargets(branchFileRevision1);
    assertEquals(0, branchCommit1Children.length);
}
Also used : IFileHistory(org.eclipse.team.core.history.IFileHistory) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFileRevision(org.eclipse.team.core.history.IFileRevision) ArrayList(java.util.ArrayList) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 9 with IFileHistory

use of org.eclipse.team.core.history.IFileHistory in project egit by eclipse.

the class HistoryTest method assertFullHistoryMatches.

private void assertFullHistoryMatches(IFile target, List<RevCommit> expectedHistory) throws CoreException {
    // Whatever the position of HEAD, the history should be the same
    for (RevCommit commit : commits) {
        testRepository.checkoutBranch(commit.getName());
        final IFileHistory history = historyProvider.getFileHistoryFor(target, IFileHistoryProvider.NONE, new NullProgressMonitor());
        assertNotNull(history);
        final IFileRevision[] revisions = history.getFileRevisions();
        assertEquals(expectedHistory.size(), revisions.length);
        final List<RevCommit> commitList = new ArrayList<RevCommit>(expectedHistory);
        assertMatchingRevisions(Arrays.asList(revisions), commitList);
    }
}
Also used : IFileHistory(org.eclipse.team.core.history.IFileHistory) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFileRevision(org.eclipse.team.core.history.IFileRevision) ArrayList(java.util.ArrayList) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 10 with IFileHistory

use of org.eclipse.team.core.history.IFileHistory in project egit by eclipse.

the class HistoryTest method queryFile2Contributors.

@Test
public void queryFile2Contributors() {
    final IFileHistory history = historyProvider.getFileHistoryFor(iFile2, IFileHistoryProvider.NONE, new NullProgressMonitor());
    assertNotNull(history);
    final IFileRevision[] revisions = history.getFileRevisions();
    IFileRevision masterFileRevision3 = null;
    IFileRevision masterFileRevision2 = null;
    IFileRevision branchFileRevision2 = null;
    for (IFileRevision revision : revisions) {
        final String revisionId = revision.getContentIdentifier();
        if (masterCommit3.getName().equals(revisionId))
            masterFileRevision3 = revision;
        else if (masterCommit2.getName().equals(revisionId))
            masterFileRevision2 = revision;
        else if (branchCommit2.getName().equals(revisionId))
            branchFileRevision2 = revision;
    }
    assertNotNull(masterFileRevision3);
    assertNotNull(masterFileRevision2);
    assertNotNull(branchFileRevision2);
    final IFileRevision[] masterCommit3Parents = history.getContributors(masterFileRevision3);
    assertEquals(1, masterCommit3Parents.length);
    assertRevisionMatchCommit(masterCommit3Parents[0], masterCommit2);
    /*
		 * The direct parent of masterCommit2 is the initial commit,
		 * masterCommit1. However, file2 was not included in that commit. We
		 * thus expect no parent.
		 */
    final IFileRevision[] masterCommit2Parents = history.getContributors(masterFileRevision2);
    assertEquals(0, masterCommit2Parents.length);
    final IFileRevision[] branchCommit2Parents = history.getContributors(branchFileRevision2);
    assertEquals(1, branchCommit2Parents.length);
    assertRevisionMatchCommit(branchCommit2Parents[0], masterCommit2);
}
Also used : IFileHistory(org.eclipse.team.core.history.IFileHistory) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFileRevision(org.eclipse.team.core.history.IFileRevision) Test(org.junit.Test)

Aggregations

IFileHistory (org.eclipse.team.core.history.IFileHistory)17 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)16 IFileRevision (org.eclipse.team.core.history.IFileRevision)16 Test (org.junit.Test)15 GitProvider (org.eclipse.egit.core.GitProvider)8 IFileHistoryProvider (org.eclipse.team.core.history.IFileHistoryProvider)8 RevCommit (org.eclipse.jgit.revwalk.RevCommit)5 ArrayList (java.util.ArrayList)3 IFile (org.eclipse.core.resources.IFile)2 IStorage (org.eclipse.core.resources.IStorage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 IProject (org.eclipse.core.resources.IProject)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)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 GitResourceVariantTreeSubscriber (org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber)1 GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)1 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)1