Source:
private void addIgnore(IProgressMonitor monitor, IPath path) throws UnsupportedEncodingException, CoreException, IOException { IPath parent = path.removeLastSegments(1); IResource resource = ResourceUtil.getResourceForLocation(path); IContainer container = null; boolean isDirectory = false; if (resource != null) { isDirectory = resource instanceof IContainer; container = resource.getParent(); } else isDirectory = path.toFile().isDirectory(); StringBuilder b = new StringBuilder("/" + path.lastSegment()); if (isDirectory) b.append('/'); b.append('\n'); String entry = b.toString(); if (container == null || container instanceof IWorkspaceRoot) { Repository repository = RepositoryMapping.getMapping( path).getRepository(); IPath gitIgnorePath = parent.append(Constants.GITIGNORE_FILENAME); IPath repoPath = new Path(repository.getWorkTree() .getAbsolutePath()); if (!repoPath.isPrefixOf(gitIgnorePath)) { String message = NLS.bind( CoreText.IgnoreOperation_parentOutsideRepo, path.toOSString(), repoPath.toOSString()); IStatus status = Activator.error(message, null); throw new CoreException(status); } File gitIgnore = new File(gitIgnorePath.toOSString()); updateGitIgnore(gitIgnore, entry); gitignoreOutsideWSChanged = true; } else { IFile gitignore = container.getFile(new Path( Constants.GITIGNORE_FILENAME)); entry = getEntry(gitignore.getLocation().toFile(), entry); IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1); ByteArrayInputStream entryBytes = asStream(entry); if (gitignore.exists()) gitignore.appendContents(entryBytes, true, true, subMonitor); else gitignore.create(entryBytes, true, subMonitor); } }

Target:
private void addIgnore(IProgressMonitor monitor, IPath path) throws UnsupportedEncodingException, CoreException, IOException { IPath parent = path.removeLastSegments(1); IResource resource = ResourceUtil.getResourceForLocation(path); IContainer container = null; boolean isDirectory = false; if (resource != null) { isDirectory = resource instanceof IContainer; container = resource.getParent(); } else isDirectory = path.toFile().isDirectory(); StringBuilder b = new StringBuilder('/'); b.append(path.lastSegment()); if (isDirectory) b.append('/'); b.append('\n'); String entry = b.toString(); if (container == null || container instanceof IWorkspaceRoot) { Repository repository = RepositoryMapping.getMapping( path).getRepository(); IPath gitIgnorePath = parent.append(Constants.GITIGNORE_FILENAME); IPath repoPath = new Path(repository.getWorkTree() .getAbsolutePath()); if (!repoPath.isPrefixOf(gitIgnorePath)) { String message = NLS.bind( CoreText.IgnoreOperation_parentOutsideRepo, path.toOSString(), repoPath.toOSString()); IStatus status = Activator.error(message, null); throw new CoreException(status); } File gitIgnore = new File(gitIgnorePath.toOSString()); updateGitIgnore(gitIgnore, entry); gitignoreOutsideWSChanged = true; } else { IFile gitignore = container.getFile(new Path( Constants.GITIGNORE_FILENAME)); entry = getEntry(gitignore.getLocation().toFile(), entry); IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1); ByteArrayInputStream entryBytes = asStream(entry); if (gitignore.exists()) gitignore.appendContents(entryBytes, true, true, subMonitor); else gitignore.create(entryBytes, true, subMonitor); } }