Search in sources :

Example 1 with IgnoreOperation

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

the class IgnoreOperationTest method testIgnoreNoTrailingNewline.

@Test
public void testIgnoreNoTrailingNewline() throws Exception {
    String existing = "/nonewline";
    IFile ignore = project.getProject().getFile(Constants.GITIGNORE_FILENAME);
    assertFalse(ignore.exists());
    ignore.create(new ByteArrayInputStream(existing.getBytes("UTF-8")), IResource.FORCE, new NullProgressMonitor());
    IFolder binFolder = project.getProject().getFolder("bin");
    IgnoreOperation operation = executeIgnore(binFolder.getLocation());
    String content = project.getFileContent(Constants.GITIGNORE_FILENAME);
    assertEquals(existing + "\n/bin/\n", content);
    assertFalse(operation.isGitignoreOutsideWSChanged());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) IgnoreOperation(org.eclipse.egit.core.op.IgnoreOperation) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 2 with IgnoreOperation

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

the class IgnoreOperationTest method testIgnoreFileCancel.

@Test
public void testIgnoreFileCancel() throws Exception {
    IFolder binFolder = project.getProject().getFolder("bin");
    IgnoreOperation operation = new IgnoreOperation(Arrays.asList(binFolder.getLocation()));
    NullProgressMonitor monitor = new NullProgressMonitor();
    monitor.setCanceled(true);
    operation.execute(monitor);
    assertFalse(project.getProject().getFile(Constants.GITIGNORE_FILENAME).exists());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IgnoreOperation(org.eclipse.egit.core.op.IgnoreOperation) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 3 with IgnoreOperation

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

the class IgnoreOperationTest method testIgnoreProject.

@Test
public void testIgnoreProject() throws Exception {
    IgnoreOperation operation = executeIgnore(project.getProject().getLocation());
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    File rootFile = root.getRawLocation().toFile();
    File ignoreFile = new File(rootFile, Constants.GITIGNORE_FILENAME);
    String content = testUtils.slurpAndClose(ignoreFile.toURI().toURL().openStream());
    assertEquals("/.metadata/\n/" + project.getProject().getName() + "/\n", content);
    assertTrue(operation.isGitignoreOutsideWSChanged());
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IgnoreOperation(org.eclipse.egit.core.op.IgnoreOperation) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Example 4 with IgnoreOperation

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

the class IgnoreOperationTest method testIgnoreWithResource.

@Test
public void testIgnoreWithResource() throws Exception {
    IFolder binFolder = project.getProject().getFolder("bin");
    Collection<IPath> c = Collections.singletonList(binFolder.getLocation());
    IgnoreOperation operation = new IgnoreOperation(c);
    operation.execute(new NullProgressMonitor());
    String content = project.getFileContent(Constants.GITIGNORE_FILENAME);
    assertEquals("/bin/\n", content);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) IgnoreOperation(org.eclipse.egit.core.op.IgnoreOperation) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 5 with IgnoreOperation

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

the class IgnoreOperationTest method testIgnoreFolder.

@Test
public void testIgnoreFolder() throws Exception {
    IFolder binFolder = project.getProject().getFolder("bin");
    IgnoreOperation operation = executeIgnore(binFolder.getLocation());
    String content = project.getFileContent(Constants.GITIGNORE_FILENAME);
    assertEquals("/bin/\n", content);
    assertFalse(operation.isGitignoreOutsideWSChanged());
}
Also used : IgnoreOperation(org.eclipse.egit.core.op.IgnoreOperation) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Aggregations

IgnoreOperation (org.eclipse.egit.core.op.IgnoreOperation)10 Test (org.junit.Test)8 IFolder (org.eclipse.core.resources.IFolder)5 IFile (org.eclipse.core.resources.IFile)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 IPath (org.eclipse.core.runtime.IPath)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 TestProject (org.eclipse.egit.core.test.TestProject)1 Shell (org.eclipse.swt.widgets.Shell)1