List of usage examples for org.eclipse.jgit.lib IndexDiff setFilter
public void setFilter(TreeFilter filter)
From source file:com.stormcloud.ide.api.git.GitManager.java
License:Open Source License
@Override public String getStatus(String file, String userHome) throws GitManagerException { String tmpRelativePath = new File(file).getAbsolutePath().replaceFirst(userHome + "/projects", "") .replaceFirst("/", ""); String project;//from w ww . j a va 2 s . c o m if (tmpRelativePath.contains("/")) { project = tmpRelativePath.substring(0, tmpRelativePath.indexOf('/')); } else { project = tmpRelativePath; } String repository = userHome + "/projects/" + project; String relativePath = tmpRelativePath.replaceFirst(project, "").replaceFirst("/", ""); String status = "unmodified"; try { Git git = Git.open(new File(repository)); IndexDiff diff = new IndexDiff(git.getRepository(), "HEAD", new FileTreeIterator(git.getRepository())); diff.setFilter(PathFilterGroup.createFromStrings(relativePath)); diff.diff(); if (!diff.getModified().isEmpty() || !diff.getChanged().isEmpty()) { return "modified"; } if (!diff.getMissing().isEmpty() || !diff.getRemoved().isEmpty()) { return "missing"; } if (!diff.getUntracked().isEmpty() || !diff.getUntrackedFolders().isEmpty() || !diff.getAdded().isEmpty()) { return "untracked"; } if (!diff.getConflicting().isEmpty()) { return "conflict"; } return status; } catch (IOException e) { LOG.error(e); throw new GitManagerException(e); } }
From source file:org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry.java
License:Open Source License
private IndexDiffData calcIndexDiffDataIncremental(IProgressMonitor monitor, String jobName, Collection<String> filesToUpdate, Collection<IResource> resourcesToUpdate) throws IOException { if (indexDiffData == null) // Incremental update not possible without prior indexDiffData // -> do full refresh instead return calcIndexDiffDataFull(monitor, jobName); EclipseGitProgressTransformer jgitMonitor = new EclipseGitProgressTransformer(monitor); List<String> treeFilterPaths = calcTreeFilterPaths(filesToUpdate); WorkingTreeIterator iterator = IteratorService.createInitialIterator(repository); if (iterator == null) return null; // workspace is closed IndexDiff diffForChangedResources = new IndexDiff(repository, Constants.HEAD, iterator); diffForChangedResources.setFilter(PathFilterGroup.createFromStrings(treeFilterPaths)); diffForChangedResources.diff(jgitMonitor, 0, 0, jobName); return new IndexDiffData(indexDiffData, filesToUpdate, resourcesToUpdate, diffForChangedResources); }
From source file:org.eclipse.egit.ui.internal.actions.CompareIndexWithHeadActionHandler.java
License:Open Source License
private boolean isStaged(Repository repository, IPath location) { String resRelPath = RepositoryMapping.getMapping(location).getRepoRelativePath(location); // This action at the moment only works for files anyway if (resRelPath == null || resRelPath.length() == 0) { return false; }// w w w . j ava2s . co m try { FileTreeIterator fileTreeIterator = new FileTreeIterator(repository); IndexDiff indexDiff = new IndexDiff(repository, Constants.HEAD, fileTreeIterator); indexDiff.setFilter(PathFilterGroup.createFromStrings(Collections.singletonList(resRelPath))); indexDiff.diff(); return indexDiff.getAdded().contains(resRelPath) || indexDiff.getChanged().contains(resRelPath) || indexDiff.getRemoved().contains(resRelPath); } catch (IOException e) { Activator.error(NLS.bind(UIText.GitHistoryPage_errorLookingUpPath, location.toString()), e); return false; } }
From source file:org.eclipse.egit.ui.internal.dialogs.CommitDialog.java
License:Open Source License
/** Retrieve file status * @param file/*from w ww . ja v a 2s .c o m*/ * @return file status * @throws IOException */ private static String getFileStatus(IFile file) throws IOException { RepositoryMapping mapping = RepositoryMapping.getMapping(file); String path = mapping.getRepoRelativePath(file); Repository repo = mapping.getRepository(); AdaptableFileTreeIterator fileTreeIterator = new AdaptableFileTreeIterator(repo, ResourcesPlugin.getWorkspace().getRoot()); IndexDiff indexDiff = new IndexDiff(repo, Constants.HEAD, fileTreeIterator); Set<String> repositoryPaths = Collections.singleton(path); indexDiff.setFilter(PathFilterGroup.createFromStrings(repositoryPaths)); indexDiff.diff(); return getFileStatus(path, indexDiff); }
From source file:org.jboss.tools.openshift.express.internal.ui.server.CommitDialog.java
License:Open Source License
/** Retrieve file status * @param path/*w w w .ja v a 2s .co m*/ * @return file status * @throws IOException */ private Status getFileStatus(String path) throws IOException { FileTreeIterator fileTreeIterator = new FileTreeIterator(repository); IndexDiff indexDiff = new IndexDiff(repository, Constants.HEAD, fileTreeIterator); Set<String> repositoryPaths = Collections.singleton(path); indexDiff.setFilter(PathFilterGroup.createFromStrings(repositoryPaths)); indexDiff.diff(null, 0, 0, ""); //$NON-NLS-1$ return getFileStatus(path, indexDiff); }