use of org.eclipse.egit.core.op.AddToIndexOperation in project jbosstools-openshift by jbosstools.
the class EGitUtils method addToRepository.
public static void addToRepository(Collection<IResource> resources, IProgressMonitor monitor) throws CoreException {
AddToIndexOperation add = new AddToIndexOperation(resources);
add.execute(monitor);
}
use of org.eclipse.egit.core.op.AddToIndexOperation in project egit by eclipse.
the class GitMoveDeleteHookTest method testMoveButDoNotRenameProjectOutsideWorkspaceContainingGitRepo.
/**
* Move a project outside the workspace containing a Git repository, but do not rename it.
* <p>
* Note the similarity of the code with {@link #testMoveAndRenameProjectContainingGitRepo()}
*
* @throws Exception
*/
@Test
public void testMoveButDoNotRenameProjectOutsideWorkspaceContainingGitRepo() 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.setLocationURI(URIUtil.toURI(new Path(new File(project.getWorkspaceSupplement(), "P2").getAbsolutePath())));
project.getProject().move(description, IResource.FORCE | IResource.SHALLOW, null);
IProject project2 = ResourcesPlugin.getWorkspace().getRoot().getProject(// same name
"Project-1");
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("P2").exists());
}
use of org.eclipse.egit.core.op.AddToIndexOperation 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.op.AddToIndexOperation 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.op.AddToIndexOperation 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());
}
Aggregations