use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.
the class RemoveFromIndexOperationTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
gitDir = new File(project.getProject().getLocationURI().getPath(), Constants.DOT_GIT);
testRepo = new TestRepository(gitDir);
testRepo.connect(project.getProject());
testRepo.commit("initial commit");
project2 = new TestProject(true, "Project-2");
gitDir2 = new File(project2.getProject().getLocationURI().getPath(), Constants.DOT_GIT);
testRepo2 = new TestRepository(gitDir2);
testRepo2.connect(project2.getProject());
testRepo2.commit("initial commit repo 2");
}
use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.
the class CommonUtilsTest method testResourceCompare.
@Test
public void testResourceCompare() throws Exception {
// we just want to test that we can call the JFace resource name
// comparator which itself is tested by JFace
TestProject p = new TestProject();
p.createFolder("test");
IFile f1 = p.createFile("test/z.txt", "z".getBytes("UTF-8"));
IFile f2 = p.createFile("test/d.txt", "d".getBytes("UTF-8"));
IFile f3 = p.createFile("test/a.txt", "a".getBytes("UTF-8"));
List<IResource> expected = Arrays.asList(new IResource[] { f3, f2, f1 });
List<IResource> tmp = new ArrayList<IResource>(expected);
Collections.shuffle(tmp, new Random(1));
Collections.sort(tmp, CommonUtils.RESOURCE_NAME_COMPARATOR);
assertEquals(expected, tmp);
// Clean up our mess
IProgressMonitor monitor = new NullProgressMonitor();
f1.delete(false, monitor);
f2.delete(false, monitor);
f3.delete(false, monitor);
p.getProject().getFolder("test").delete(false, monitor);
p.getProject().delete(false, monitor);
}
use of org.eclipse.egit.core.test.TestProject 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.egit.core.test.TestProject in project egit by eclipse.
the class GitResourceVariantTreeTest method shouldReturnTwoRoots.
/**
* When we have two or more project associated with repository, roots()
* method should return list of project. In this case we have two project
* associated with particular repository, therefore '2' value is expected.
*
* @throws Exception
*/
@Test
public void shouldReturnTwoRoots() throws Exception {
// when
// create second project
TestProject secondProject = new TestProject(true, "Project-2");
try {
IProject secondIProject = secondProject.project;
// add connect project with repository
new ConnectProviderOperation(secondIProject, gitDir).execute(null);
try (Git git = new Git(repo)) {
git.commit().setAuthor("JUnit", "junit@egit.org").setMessage("Initial commit").call();
}
GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, false);
GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
// given
GitResourceVariantTree grvt = new GitTestResourceVariantTree(dataSet, null, null);
// then
IResource[] roots = grvt.roots();
// sort in order to be able to assert the project instances
Arrays.sort(roots, new Comparator<IResource>() {
@Override
public int compare(IResource r1, IResource r2) {
String path1 = r1.getFullPath().toString();
String path2 = r2.getFullPath().toString();
return path1.compareTo(path2);
}
});
assertEquals(2, roots.length);
IResource actualProject = roots[0];
assertEquals(this.project.project, actualProject);
IResource actualProject1 = roots[1];
assertEquals(secondIProject, actualProject1);
} finally {
secondProject.dispose();
}
}
use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.
the class ProjectUtilTest method testRefreshRepositoryResources.
@Test
public void testRefreshRepositoryResources() throws Exception {
TestProject subdirProject = new TestProject(true, "subdir/Project-2");
new ConnectProviderOperation(project.getProject(), repository.getRepository().getDirectory()).execute(null);
new ConnectProviderOperation(subdirProject.getProject(), repository.getRepository().getDirectory()).execute(null);
IFile file1 = createOutOfSyncFile(project, "refresh1");
ProjectUtil.refreshRepositoryResources(repository.getRepository(), Arrays.asList("Project-1/refresh1"), new NullProgressMonitor());
assertTrue(file1.isSynchronized(IResource.DEPTH_ZERO));
IFile file2 = createOutOfSyncFile(project, "refresh2");
ProjectUtil.refreshRepositoryResources(repository.getRepository(), Arrays.asList("Project-1"), new NullProgressMonitor());
assertTrue(file2.isSynchronized(IResource.DEPTH_ZERO));
IFile file3 = createOutOfSyncFile(project, "refresh3");
ProjectUtil.refreshRepositoryResources(repository.getRepository(), Arrays.asList(""), new NullProgressMonitor());
assertTrue(file3.isSynchronized(IResource.DEPTH_ZERO));
IFile file4 = createOutOfSyncFile(subdirProject, "refresh4");
ProjectUtil.refreshRepositoryResources(repository.getRepository(), Arrays.asList("subdir"), new NullProgressMonitor());
assertTrue(file4.isSynchronized(IResource.DEPTH_ZERO));
}
Aggregations