Search in sources :

Example 31 with AddToIndexOperation

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

the class RemoveFromIndexOperationTest method shouldUnstExistingFile.

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

Example 32 with AddToIndexOperation

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

the class RemoveFromIndexOperationTest method shouldUnstageFilesFromMultipleRepositories.

@Test
public void shouldUnstageFilesFromMultipleRepositories() throws Exception {
    // given
    IFile fileRepo1 = testUtils.addFileToProject(project.getProject(), "1.txt", "content");
    IFile fileRepo2 = testUtils.addFileToProject(project2.getProject(), "2.txt", "content");
    new AddToIndexOperation(asList(fileRepo1)).execute(null);
    new AddToIndexOperation(asList(fileRepo2)).execute(null);
    // when
    new RemoveFromIndexOperation(Arrays.asList(fileRepo1.getLocation(), fileRepo2.getLocation())).execute(null);
    // then
    assertTrue(testRepo.removedFromIndex(fileRepo1.getLocation().toPortableString()));
    assertTrue(testRepo.removedFromIndex(fileRepo2.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 33 with AddToIndexOperation

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

the class RemoveFromIndexOperationTest method shouldUnstageFilesInNestedFolder.

@Test
public void shouldUnstageFilesInNestedFolder() throws Exception {
    // given
    IFile file1 = createFileInRepo("sub/next/a.txt");
    IFile file2 = createFileInRepo("sub/next/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 34 with AddToIndexOperation

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

the class StashCreateOperationTest method testCustomMessage.

@Test
public void testCustomMessage() throws Exception {
    IFile file = testUtils.addFileToProject(project.getProject(), "foo/a.txt", "some text");
    new AddToIndexOperation(Arrays.asList(file)).execute(null);
    String message = "stash message";
    StashCreateOperation stashCreateOperation = new StashCreateOperation(repository, message);
    stashCreateOperation.execute(null);
    try (RevWalk revWalk = new RevWalk(repository)) {
        RevCommit commit = revWalk.parseCommit(repository.resolve("stash@{0}"));
        assertEquals(message, commit.getFullMessage());
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) StashCreateOperation(org.eclipse.egit.core.op.StashCreateOperation) RevWalk(org.eclipse.jgit.revwalk.RevWalk) AddToIndexOperation(org.eclipse.egit.core.op.AddToIndexOperation) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 35 with AddToIndexOperation

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

the class TrackUntrackOperationTest method testTrackFiles.

@Test
public void testTrackFiles() throws Exception {
    final ArrayList<IFile> files = new ArrayList<IFile>();
    project.accept(new IResourceVisitor() {

        @Override
        public boolean visit(IResource resource) throws CoreException {
            if (resource instanceof IFile)
                files.add((IFile) resource);
            return true;
        }
    });
    IFile[] fileArr = files.toArray(new IFile[files.size()]);
    assertTrackedState(fileArr, false);
    AddToIndexOperation trop = new AddToIndexOperation(files);
    trop.execute(new NullProgressMonitor());
    assertTrackedState(fileArr, true);
    UntrackOperation utop = new UntrackOperation(Arrays.asList(fileArr));
    utop.execute(new NullProgressMonitor());
    assertTrackedState(fileArr, false);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) UntrackOperation(org.eclipse.egit.core.op.UntrackOperation) IResource(org.eclipse.core.resources.IResource) AddToIndexOperation(org.eclipse.egit.core.op.AddToIndexOperation) Test(org.junit.Test)

Aggregations

AddToIndexOperation (org.eclipse.egit.core.op.AddToIndexOperation)35 Test (org.junit.Test)26 IFile (org.eclipse.core.resources.IFile)25 TestProject (org.eclipse.egit.core.test.TestProject)9 DirCache (org.eclipse.jgit.dircache.DirCache)9 RemoveFromIndexOperation (org.eclipse.egit.core.op.RemoveFromIndexOperation)7 CommitOperation (org.eclipse.egit.core.op.CommitOperation)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ArrayList (java.util.ArrayList)5 IProject (org.eclipse.core.resources.IProject)5 TestRepository (org.eclipse.egit.core.test.TestRepository)5 IProjectDescription (org.eclipse.core.resources.IProjectDescription)4 IResource (org.eclipse.core.resources.IResource)4 CoreException (org.eclipse.core.runtime.CoreException)4 IPath (org.eclipse.core.runtime.IPath)4 Repository (org.eclipse.jgit.lib.Repository)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 File (java.io.File)3 IFolder (org.eclipse.core.resources.IFolder)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3