use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.
the class GitMoveDeleteHookTest method testDeleteFolder.
@Test
public void testDeleteFolder() throws Exception {
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"));
// Modify the content before the move
testUtils.changeContentOfFile(project.getProject(), project.getProject().getFile("folder/file.txt"), "other text");
project.getProject().getFolder("folder").delete(true, null);
dirCache.read();
// Unlike delete file, dircache is untouched... pretty illogical
// TODO: Change the behavior of the hook.
assertNotNull(dirCache.getEntry("folder/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 testDeleteProject.
@Test
public void testDeleteProject() throws Exception {
TestProject project = initRepoAboveProjectInsideWs("P/", "");
testUtils.addFileToProject(project.getProject(), "file.txt", "some text");
AddToIndexOperation addToIndexOperation = new AddToIndexOperation(new IResource[] { project.getProject().getFile("file.txt") });
addToIndexOperation.execute(null);
RepositoryMapping mapping = RepositoryMapping.getMapping(project.getProject());
IPath gitDirAbsolutePath = mapping.getGitDirAbsolutePath();
Repository db = FileRepositoryBuilder.create(gitDirAbsolutePath.toFile());
DirCache index = DirCache.read(db.getIndexFile(), db.getFS());
assertNotNull(index.getEntry("P/Project-1/file.txt"));
db.close();
db = null;
project.getProject().delete(true, null);
assertNull(RepositoryMapping.getMapping(project.getProject()));
// Check that the repo is still there. Being a bit paranoid we look for
// a file
assertTrue(gitDirAbsolutePath.toString(), gitDirAbsolutePath.append("HEAD").toFile().exists());
db = FileRepositoryBuilder.create(gitDirAbsolutePath.toFile());
index = DirCache.read(db.getIndexFile(), db.getFS());
// FIXME: Shouldn't we unstage deleted projects?
assertNotNull(index.getEntry("P/Project-1/file.txt"));
db.close();
}
use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.
the class GitMoveDeleteHookTest method initRepoAboveProject.
private TestProject initRepoAboveProject(String srcParent, String d, boolean insidews) throws Exception {
registerWorkspaceRelativeTestDir(srcParent);
TestProject project = new TestProject(true, srcParent + "Project-1", insidews, workspaceSupplement);
File gd = new File(insidews ? workspace : workspaceSupplement, d);
File gitDir = new File(gd, 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 testDeleteFile.
@Theory
public void testDeleteFile(boolean autoStageDelete) throws Exception {
IEclipsePreferences p = InstanceScope.INSTANCE.getNode(Activator.getPluginId());
p.putBoolean(GitCorePreferences.core_autoStageDeletion, autoStageDelete);
TestProject project = initRepoInsideProjectInsideWorkspace();
testUtils.addFileToProject(project.getProject(), "file.txt", "some text");
testUtils.addFileToProject(project.getProject(), "file2.txt", "some more text");
IFile file = project.getProject().getFile("file.txt");
AddToIndexOperation addToIndexOperation = new AddToIndexOperation(new IResource[] { file, project.getProject().getFile("file2.txt") });
addToIndexOperation.execute(null);
// Validate pre-conditions
DirCache dirCache = DirCache.read(repository.getIndexFile(), FS.DETECTED);
assertEquals(2, dirCache.getEntryCount());
assertNotNull(dirCache.getEntry("file.txt"));
assertNotNull(dirCache.getEntry("file2.txt"));
// Modify the content before the move
testUtils.changeContentOfFile(project.getProject(), file, "other text");
TestUtils.waitForJobs(500, 10000, JobFamilies.INDEX_DIFF_CACHE_UPDATE);
file.delete(true, null);
TestUtils.waitForJobs(500, 10000, JobFamilies.INDEX_DIFF_CACHE_UPDATE);
// Check index for the deleted file
dirCache.read();
if (autoStageDelete) {
assertEquals(1, dirCache.getEntryCount());
assertNull(dirCache.getEntry("file.txt"));
} else {
assertEquals(2, dirCache.getEntryCount());
assertNotNull(dirCache.getEntry("file.txt"));
}
assertNotNull(dirCache.getEntry("file2.txt"));
// Actual file is deleted
assertFalse(file.exists());
// But a non-affected file remains
assertTrue(project.getProject().getFile("file2.txt").exists());
}
use of org.eclipse.egit.core.test.TestProject in project egit by eclipse.
the class GitMoveDeleteHookTest method testMoveFile.
@Theory
public void testMoveFile(boolean autoStageMoves) throws Exception {
configureAutoStageMoves(autoStageMoves);
TestProject project = initRepoInsideProjectInsideWorkspace();
testUtils.addFileToProject(project.getProject(), "file.txt", "some text");
testUtils.addFileToProject(project.getProject(), "file2.txt", "some more text");
AddToIndexOperation addToIndexOperation = new AddToIndexOperation(new IResource[] { project.getProject().getFile("file.txt"), project.getProject().getFile("file2.txt") });
addToIndexOperation.execute(null);
// Validate pre-conditions
DirCache dirCache = DirCache.read(repository.getIndexFile(), FS.DETECTED);
assertNotNull(dirCache.getEntry("file.txt"));
assertNotNull(dirCache.getEntry("file2.txt"));
assertNull(dirCache.getEntry("data.txt"));
assertFalse(project.getProject().getFile("data.txt").exists());
ObjectId oldContentId = dirCache.getEntry("file.txt").getObjectId();
// Modify the content before the move
testUtils.changeContentOfFile(project.getProject(), project.getProject().getFile("file.txt"), "other text");
project.getProject().getFile("file.txt").move(project.getProject().getFile("data.txt").getFullPath(), false, null);
dirCache.read();
assertTrue(project.getProject().getFile("data.txt").exists());
if (autoStageMoves) {
assertNotNull(dirCache.getEntry("data.txt"));
// Same content in index as before the move
assertEquals(oldContentId, dirCache.getEntry("data.txt").getObjectId());
} else {
assertNull(dirCache.getEntry("data.txt"));
}
// Not moved file still in its old place
assertNotNull(dirCache.getEntry("file2.txt"));
}
Aggregations