Source:
private void addIgnore(IProgressMonitor monitor, IPath path) throws UnsupportedEncodingException, CoreException, IOException { SubMonitor progress = SubMonitor.convert(monitor, 100); 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) { RepositoryMapping mapping = RepositoryMapping.getMapping( path); if (mapping == null) { String message = NLS.bind( CoreText.IgnoreOperation_parentOutsideRepo, path.toOSString(), null); IStatus status = Activator.error(message, null); throw new CoreException(status); } Repository repository = mapping.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); ByteArrayInputStream entryBytes = asStream(entry); if (gitignore.exists()) gitignore.appendContents(entryBytes, true, true, progress); else gitignore.create(entryBytes, true, progress); } }

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) { RepositoryMapping mapping = RepositoryMapping.getMapping( path); if (mapping == null) { String message = NLS.bind( CoreText.IgnoreOperation_parentOutsideRepo, path.toOSString(), null); IStatus status = Activator.error(message, null); throw new CoreException(status); } Repository repository = mapping.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); ByteArrayInputStream entryBytes = asStream(entry); if (gitignore.exists()) gitignore.appendContents(entryBytes, true, true, monitor); else gitignore.create(entryBytes, true, monitor); } }