use of org.eclipse.egit.core.op.AddToIndexOperation 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.op.AddToIndexOperation 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());
}
use of org.eclipse.egit.core.op.AddToIndexOperation in project egit by eclipse.
the class GitSubscriberMergeContext method markAsMerged.
@Override
public void markAsMerged(IDiff node, boolean inSyncHint, IProgressMonitor monitor) throws CoreException {
IResource resource = getDiffTree().getResource(node);
AddToIndexOperation operation = new AddToIndexOperation(new IResource[] { resource });
operation.execute(monitor);
}
use of org.eclipse.egit.core.op.AddToIndexOperation in project egit by eclipse.
the class AddToIndexActionHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final IResource[] sel = getSelectedResources(event);
if (sel.length == 0)
return null;
IResource[] resourcesInScope;
try {
IWorkbenchPart part = getPart(event);
resourcesInScope = GitScopeUtil.getRelatedChanges(part, sel);
} catch (InterruptedException e) {
// cancels the scope operation
return null;
}
final AddToIndexOperation operation = new AddToIndexOperation(resourcesInScope);
String jobname = UIText.AddToIndexAction_addingFiles;
Job job = new Job(jobname) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
operation.execute(monitor);
} catch (CoreException e) {
return Activator.createErrorStatus(e.getStatus().getMessage(), e);
}
return Status.OK_STATUS;
}
@Override
public boolean belongsTo(Object family) {
if (JobFamilies.ADD_TO_INDEX.equals(family))
return true;
return super.belongsTo(family);
}
};
job.setUser(true);
job.setRule(operation.getSchedulingRule());
job.schedule();
return null;
}
use of org.eclipse.egit.core.op.AddToIndexOperation in project jbosstools-openshift by jbosstools.
the class EGitUtils method addToRepository.
public static void addToRepository(IProject project, Repository repository, IProgressMonitor monitor) throws CoreException {
AddToIndexOperation add = new AddToIndexOperation(Collections.singletonList(project));
add.execute(monitor);
}
Aggregations