use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.
the class GitMoveDeleteHookTest method dotestMoveProjectWithinRepo.
private void dotestMoveProjectWithinRepo(String srcParent, String srcProjectName, String dstParent, String dstProjecName, String gitDir, boolean sourceInsideWs, boolean autoStageMoves) throws Exception {
configureAutoStageMoves(autoStageMoves);
String gdRelativeSrcParent = srcParent + srcProjectName + "/";
if (gdRelativeSrcParent.startsWith(gitDir))
gdRelativeSrcParent = gdRelativeSrcParent.substring(gitDir.length());
testDirs.add(new File(dstParent));
String gdRelativeDstParent = dstParent + dstProjecName + "/";
if (gdRelativeDstParent.startsWith(gitDir))
gdRelativeDstParent = gdRelativeDstParent.substring(gitDir.length());
registerWorkspaceRelativeTestDirProject(srcParent, srcProjectName);
registerWorkspaceRelativeTestDirProject(dstParent, dstProjecName);
// Old cruft may be laying around
TestProject project = initRepoAboveProject(srcParent, gitDir, sourceInsideWs);
IProject project0 = project.getProject().getWorkspace().getRoot().getProject(dstProjecName);
project0.delete(true, null);
testUtils.addFileToProject(project.getProject(), "file.txt", "some text");
AddToIndexOperation addToIndexOperation = new AddToIndexOperation(new IResource[] { project.getProject().getFile("file.txt") });
addToIndexOperation.execute(null);
// Check condition before move
DirCache dirCache = DirCache.read(repository.getIndexFile(), FS.DETECTED);
assertNotNull(dirCache.getEntry(gdRelativeSrcParent + "file.txt"));
ObjectId oldContentId = dirCache.getEntry(gdRelativeSrcParent + "file.txt").getObjectId();
// Modify the content before the move, we want to see the staged content
// as it was before the move in the index
testUtils.changeContentOfFile(project.getProject(), project.getProject().getFile("file.txt"), "other text");
IProjectDescription description = project.getProject().getDescription();
description.setName(dstProjecName);
if (sourceInsideWs)
if (dstParent.length() > 0)
description.setLocationURI(URIUtil.toURI(project.getProject().getWorkspace().getRoot().getLocation().append(dstParent + dstProjecName)));
else
description.setLocationURI(null);
else
description.setLocationURI(URIUtil.toURI(new Path(workspaceSupplement + "/" + dstParent + "/" + dstProjecName)));
project.getProject().move(description, IResource.FORCE | IResource.SHALLOW, null);
IProject project2 = project.getProject().getWorkspace().getRoot().getProject(dstProjecName);
assertTrue(project2.exists());
assertNotNull(RepositoryMapping.getMapping(project2));
// Check that our file exists on disk has a new location in the index
dirCache.read();
assertTrue(project2.getFile("file.txt").exists());
if (autoStageMoves) {
assertNotNull(dirCache.getEntry(gdRelativeDstParent + "file.txt"));
// Same content in index as before the move, i.e. not same as on
// disk
assertEquals(oldContentId, dirCache.getEntry(gdRelativeDstParent + "file.txt").getObjectId());
} else {
assertNull(dirCache.getEntry(gdRelativeDstParent + "file.txt"));
}
}
use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.
the class GitMoveDeleteHookTest method testMoveFolderWithFileWithConflictsShouldBeCanceled.
@Theory
public void testMoveFolderWithFileWithConflictsShouldBeCanceled(boolean autoStageMoves) throws Exception {
configureAutoStageMoves(autoStageMoves);
TestProject project = initRepoInsideProjectInsideWorkspace();
String filePath = "folder/file.txt";
IFile file = testUtils.addFileToProject(project.getProject(), filePath, "some text");
Repository repo = testRepository.getRepository();
DirCache index = repo.lockDirCache();
DirCacheBuilder builder = index.builder();
addUnmergedEntry(filePath, builder);
builder.commit();
try {
project.getProject().getFolder("folder").move(project.getProject().getFolder("newfolder").getFullPath(), false, null);
fail("Expected move of folder with file with conflicts to fail.");
} catch (CoreException e) {
IStatus status = e.getStatus();
assertNotNull(status);
assertEquals(IStatus.WARNING, status.getSeverity());
}
assertTrue("File should still exist at old location", file.exists());
DirCache indexAfter = repo.readDirCache();
DirCacheEntry entry = indexAfter.getEntry(filePath);
assertEquals("Expected entry to still be in non-zero (conflict) stage", DirCacheEntry.STAGE_1, entry.getStage());
}
use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.
the class GitMoveDeleteHookTest method initRepoInsideProjectOutsideWorkspace.
private TestProject initRepoInsideProjectOutsideWorkspace() throws Exception {
TestProject project = new TestProject(true, "Project-1", false, 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());
return project;
}
use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.
the class GitMoveDeleteHookTest method testMoveFileWithConflictsShouldBeCanceled.
@Theory
public void testMoveFileWithConflictsShouldBeCanceled(boolean autoStageMoves) throws Exception {
configureAutoStageMoves(autoStageMoves);
TestProject project = initRepoInsideProjectInsideWorkspace();
String filePath = "file.txt";
IFile file = testUtils.addFileToProject(project.getProject(), filePath, "some text");
Repository repo = testRepository.getRepository();
DirCache index = repo.lockDirCache();
DirCacheBuilder builder = index.builder();
addUnmergedEntry(filePath, builder);
builder.commit();
try {
file.move(new Path("destination.txt"), false, null);
fail("Expected move of file with conflicts to fail.");
} catch (CoreException e) {
IStatus status = e.getStatus();
assertNotNull(status);
assertEquals(IStatus.WARNING, status.getSeverity());
}
assertTrue("File should still exist at old location", file.exists());
DirCache indexAfter = repo.readDirCache();
DirCacheEntry entry = indexAfter.getEntry(filePath);
assertEquals("Expected entry to still be in non-zero (conflict) stage", DirCacheEntry.STAGE_1, entry.getStage());
}
use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.
the class GitMoveDeleteHookTest method testMoveAndRenameProjectContainingGitRepo.
/**
* Rename and move a project in the workspace containing a Git repository.
* <p>
* The repository will be moved with the project.
* Note that there is no way to rename a project in the workspace without
* moving it. See https://bugs.eclipse.org/358828 for a discussion.
*
* @throws Exception
*/
@Test
public void testMoveAndRenameProjectContainingGitRepo() throws Exception {
ResourcesPlugin.getWorkspace().getRoot().getProject("Project-1").delete(true, null);
ResourcesPlugin.getWorkspace().getRoot().getProject("P2").delete(true, null);
TestProject project = initRepoInsideProjectInsideWorkspace();
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");
registerWorkspaceRelativeTestDir("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("P2", 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