Search in sources :

Example 1 with RemoveFromIndexOperation

use of org.eclipse.egit.core.op.RemoveFromIndexOperation in project egit by eclipse.

the class RemoveFromIndexOperationTest method shouldUnTrackFile.

@Test
public void shouldUnTrackFile() throws Exception {
    // given
    IFile file1 = createFileInRepo("a.txt");
    new AddToIndexOperation(asList(file1)).execute(null);
    // when
    new RemoveFromIndexOperation(Arrays.asList(file1.getLocation())).execute(null);
    // then
    assertTrue(testRepo.removedFromIndex(file1.getLocation().toPortableString()));
}
Also used : IFile(org.eclipse.core.resources.IFile) RemoveFromIndexOperation(org.eclipse.egit.core.op.RemoveFromIndexOperation) AddToIndexOperation(org.eclipse.egit.core.op.AddToIndexOperation) Test(org.junit.Test)

Example 2 with RemoveFromIndexOperation

use of org.eclipse.egit.core.op.RemoveFromIndexOperation in project egit by eclipse.

the class RemoveFromIndexOperationTest method shouldRemoveFromIndexOnInitialCommit.

@Test
public void shouldRemoveFromIndexOnInitialCommit() throws Exception {
    testRepo.dispose();
    FileUtils.delete(gitDir, FileUtils.RECURSIVE | FileUtils.RETRY);
    testRepo = new TestRepository(gitDir);
    testRepo.connect(project.getProject());
    IFile file = testUtils.addFileToProject(project.getProject(), "file.txt", "content");
    new AddToIndexOperation(asList(file)).execute(null);
    assertTrue(testRepo.inIndex(file.getLocation().toString()));
    new RemoveFromIndexOperation(Arrays.asList(file.getLocation())).execute(null);
    assertFalse(testRepo.inIndex(file.getLocation().toString()));
    assertTrue(file.getLocation().toFile().exists());
}
Also used : TestRepository(org.eclipse.egit.core.test.TestRepository) IFile(org.eclipse.core.resources.IFile) RemoveFromIndexOperation(org.eclipse.egit.core.op.RemoveFromIndexOperation) AddToIndexOperation(org.eclipse.egit.core.op.AddToIndexOperation) Test(org.junit.Test)

Example 3 with RemoveFromIndexOperation

use of org.eclipse.egit.core.op.RemoveFromIndexOperation in project egit by eclipse.

the class RemoveFromIndexOperationTest method shouldUnstageFilesInFolder.

@Test
public void shouldUnstageFilesInFolder() throws Exception {
    // given
    IFile file1 = createFileInRepo("sub/a.txt");
    IFile file2 = createFileInRepo("sub/b.txt");
    IFolder container = project.getProject().getFolder("sub");
    List<IFolder> addResources = asList(project.getProject().getFolder("sub"));
    new AddToIndexOperation(addResources).execute(null);
    testRepo.commit("first commit");
    Thread.sleep(1000);
    file1.setContents(new ByteArrayInputStream("other text".getBytes(project.project.getDefaultCharset())), 0, null);
    file2.setContents(new ByteArrayInputStream("other text".getBytes(project.project.getDefaultCharset())), 0, null);
    new AddToIndexOperation(addResources).execute(null);
    // when
    new RemoveFromIndexOperation(asList(container.getLocation())).execute(null);
    // then
    assertTrue(testRepo.removedFromIndex(file1.getLocation().toPortableString()));
    assertTrue(testRepo.removedFromIndex(file2.getLocation().toPortableString()));
}
Also used : IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) RemoveFromIndexOperation(org.eclipse.egit.core.op.RemoveFromIndexOperation) IFolder(org.eclipse.core.resources.IFolder) AddToIndexOperation(org.eclipse.egit.core.op.AddToIndexOperation) Test(org.junit.Test)

Example 4 with RemoveFromIndexOperation

use of org.eclipse.egit.core.op.RemoveFromIndexOperation in project egit by eclipse.

the class RemoveFromIndexActionHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IPath[] sel = getSelectedLocations(event);
    if (sel.length == 0)
        return null;
    final RemoveFromIndexOperation removeOperation = new RemoveFromIndexOperation(Arrays.asList(sel));
    Job job = new Job(UIText.RemoveFromIndexAction_removingFiles) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                removeOperation.execute(monitor);
            } catch (CoreException e) {
                return Activator.createErrorStatus(e.getStatus().getMessage(), e);
            } finally {
                monitor.done();
            }
            return Status.OK_STATUS;
        }

        @Override
        public boolean belongsTo(Object family) {
            if (JobFamilies.REMOVE_FROM_INDEX.equals(family))
                return true;
            return super.belongsTo(family);
        }
    };
    job.setUser(true);
    job.setRule(removeOperation.getSchedulingRule());
    job.schedule();
    return null;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) Job(org.eclipse.core.runtime.jobs.Job) RemoveFromIndexOperation(org.eclipse.egit.core.op.RemoveFromIndexOperation)

Example 5 with RemoveFromIndexOperation

use of org.eclipse.egit.core.op.RemoveFromIndexOperation in project egit by eclipse.

the class RemoveFromIndexOperationTest method shouldUnTrackFilesInFolder.

@Test
public void shouldUnTrackFilesInFolder() throws Exception {
    // given
    IFile file1 = createFileInRepo("sub/a.txt");
    IFile file2 = createFileInRepo("sub/b.txt");
    IFolder container = project.getProject().getFolder("sub");
    new AddToIndexOperation(asList(file1, file2)).execute(null);
    // when
    new RemoveFromIndexOperation(asList(container.getLocation())).execute(null);
    // then
    assertTrue(testRepo.removedFromIndex(file1.getLocation().toPortableString()));
    assertTrue(testRepo.removedFromIndex(file2.getLocation().toPortableString()));
}
Also used : IFile(org.eclipse.core.resources.IFile) RemoveFromIndexOperation(org.eclipse.egit.core.op.RemoveFromIndexOperation) IFolder(org.eclipse.core.resources.IFolder) AddToIndexOperation(org.eclipse.egit.core.op.AddToIndexOperation) Test(org.junit.Test)

Aggregations

RemoveFromIndexOperation (org.eclipse.egit.core.op.RemoveFromIndexOperation)8 IFile (org.eclipse.core.resources.IFile)7 AddToIndexOperation (org.eclipse.egit.core.op.AddToIndexOperation)7 Test (org.junit.Test)7 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IFolder (org.eclipse.core.resources.IFolder)3 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 TestRepository (org.eclipse.egit.core.test.TestRepository)1