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);
}
}
}
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();
}
}
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);
}
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);
}
}
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);
}
Aggregations