use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.
the class ProjectUtilTest method testGetNestedProjectsContains.
@Test
public void testGetNestedProjectsContains() throws Exception {
TestProject prj2 = new TestProject(true, "Project-1/dir/Project-1-sub");
try {
repository.createFile(project.getProject(), "xxx");
repository.createFile(project.getProject(), "zzz");
repository.createFile(prj2.getProject(), "zzz");
project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
prj2.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
IProject[] projectsContaining = ProjectUtil.getProjectsContaining(repository.getRepository(), Collections.singleton("Project-1/xxx"));
IProject[] projectsEmpty = ProjectUtil.getProjectsContaining(repository.getRepository(), Collections.singleton("yyy"));
IProject[] projectSelf = ProjectUtil.getProjectsContaining(repository.getRepository(), Collections.singleton("Project-1"));
Set<String> files = new TreeSet<String>();
files.add("Project-1/xxx");
files.add("Project-1/zzz");
IProject[] multiFile = ProjectUtil.getProjectsContaining(repository.getRepository(), files);
files.clear();
files.add("Project-1/dir/Project-1-sub/zzz");
files.add("Project-1/xxx");
IProject[] multiProject = ProjectUtil.getProjectsContaining(repository.getRepository(), files);
IProject[] nonExistProject = ProjectUtil.getProjectsContaining(repository.getRepository(), Collections.singleton("Project-2"));
assertEquals(1, projectsContaining.length);
assertEquals(0, projectsEmpty.length);
assertEquals(1, projectSelf.length);
assertEquals(1, multiFile.length);
assertEquals(2, multiProject.length);
assertEquals(0, nonExistProject.length);
IProject p = projectsContaining[0];
assertEquals("Project-1", p.getDescription().getName());
} finally {
prj2.dispose();
}
}
use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.
the class ResourceUtilTest method getFileForLocationShouldReturnExistingFileInCaseOfNestedProject.
@Ignore
@Test
public void getFileForLocationShouldReturnExistingFileInCaseOfNestedProject() throws Exception {
TestProject nested = new TestProject(true, "Project-1/Project-2");
connect(nested.getProject());
IFile file = nested.createFile("a.txt", new byte[] {});
IPath location = file.getLocation();
IFile result = ResourceUtil.getFileForLocation(location, false);
assertThat(result, notNullValue());
assertTrue("Returned IFile should exist", result.exists());
assertThat(result.getProject(), is(project.getProject()));
result = ResourceUtil.getFileForLocation(location, true);
assertThat(result, notNullValue());
assertTrue("Returned IFile should exist", result.exists());
assertThat(result.getProject(), is(nested.getProject()));
}
use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.
the class GitMoveDeleteHookTest method initRepoInsideProjectInsideWorkspace.
private TestProject initRepoInsideProjectInsideWorkspace() throws Exception {
TestProject project = new TestProject(true, "Project-1", true, workspaceSupplement);
File gitDir = new File(project.getProject().getLocationURI().getPath(), Constants.DOT_GIT);
testDirs.add(gitDir);
testRepository = new TestRepository(gitDir);
repository = testRepository.getRepository();
testRepository.connect(project.getProject());
registerWorkspaceRelativeTestDir("Project-1");
return project;
}
use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.
the class GitMoveDeleteHookTest method testMoveFolder.
/**
* Rename "folder" to "dir".
* @param autoStageMoves
* @throws Exception
*/
@Theory
public void testMoveFolder(boolean autoStageMoves) throws Exception {
configureAutoStageMoves(autoStageMoves);
TestProject project = initRepoInsideProjectInsideWorkspace();
testUtils.addFileToProject(project.getProject(), "folder/file.txt", "some text");
testUtils.addFileToProject(project.getProject(), "folder2/file.txt", "some other text");
AddToIndexOperation addToIndexOperation = new AddToIndexOperation(new IResource[] { project.getProject().getFile("folder/file.txt"), project.getProject().getFile("folder2/file.txt") });
addToIndexOperation.execute(null);
DirCache dirCache = DirCache.read(repository.getIndexFile(), FS.DETECTED);
assertNotNull(dirCache.getEntry("folder/file.txt"));
assertNotNull(dirCache.getEntry("folder2/file.txt"));
assertNull(dirCache.getEntry("dir/file.txt"));
assertFalse(project.getProject().getFile("dir/file.txt").exists());
ObjectId oldContentId = dirCache.getEntry("folder/file.txt").getObjectId();
// Modify the content before the move
testUtils.changeContentOfFile(project.getProject(), project.getProject().getFile("folder/file.txt"), "other text");
project.getProject().getFolder("folder").move(project.getProject().getFolder("dir").getFullPath(), false, null);
dirCache.read();
assertTrue(project.getProject().getFile("dir/file.txt").exists());
if (autoStageMoves) {
assertNull(dirCache.getEntry("folder/file.txt"));
assertNotNull(dirCache.getEntry("dir/file.txt"));
// Same content in index as before the move
assertEquals(oldContentId, dirCache.getEntry("dir/file.txt").getObjectId());
} else {
assertNotNull(dirCache.getEntry("folder/file.txt"));
assertNull(dirCache.getEntry("dir/file.txt"));
}
// Not moved file still there
assertNotNull(dirCache.getEntry("folder2/file.txt"));
}
use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.
the class GitMoveDeleteHookTest method testRenameProjectOutsideWorkspaceContainingGitRepo.
/**
* Rename a project outside the workspace containing a Git repository.
* <p>
* Note the similarity of the code with {@link #testMoveAndRenameProjectContainingGitRepo()}
*
* @throws Exception
*/
@Test
public void testRenameProjectOutsideWorkspaceContainingGitRepo() throws Exception {
ResourcesPlugin.getWorkspace().getRoot().getProject("Project-1").delete(true, null);
ResourcesPlugin.getWorkspace().getRoot().getProject("P2").delete(true, null);
TestProject project = initRepoInsideProjectOutsideWorkspace();
testUtils.addFileToProject(project.getProject(), "file.txt", "some text");
AddToIndexOperation addToIndexOperation = new AddToIndexOperation(new IResource[] { project.getProject().getFile("file.txt") });
addToIndexOperation.execute(null);
IProjectDescription description = project.getProject().getDescription();
description.setName("P2");
project.getProject().move(description, IResource.FORCE | IResource.SHALLOW, null);
IProject project2 = ResourcesPlugin.getWorkspace().getRoot().getProject("P2");
assertNotNull(RepositoryMapping.getMapping(project2.getProject()));
Repository movedRepo = RepositoryMapping.getMapping(project2).getRepository();
assertEquals("Project-1", movedRepo.getDirectory().getParentFile().getName());
DirCache dc = movedRepo.readDirCache();
assertEquals(1, dc.getEntryCount());
assertEquals("file.txt", dc.getEntry(0).getPathString());
assertFalse(ResourcesPlugin.getWorkspace().getRoot().getProject("Project-1").exists());
}
Aggregations