private void logStatus(final Git git) throws GitAPIException { final Status status = git.status().call(); if (!status.getAdded().isEmpty()) { LOG.info("Added files {}", status.getAdded()); } if (!status.getChanged().isEmpty()) { LOG.info("Changed files {}", status.getChanged()); } if (!status.getRemoved().isEmpty()) { LOG.info("Removed files {}", status.getRemoved()); } if (!status.getModified().isEmpty()) { LOG.info("Modified files {}", status.getModified()); } if (!status.getMissing().isEmpty()) { LOG.info("Missing files {}", status.getMissing()); } }
/** * Returns <code>true</code> if the given repository has uncommitted changes. Uncommitted changes * taken into account are * * <ul> * <li>freshly added (but uncommitted resources) * <li>changed (but uncommitted) * <li>modified (but uncommitted resources) * <li>removed (but uncommitted resources) * </ul> * * @param repository the repository to check for uncommitted changes * @return * @throws IOException * @throws NoWorkTreeException * @throws GitAPIException */ public static boolean isDirty(Repository repository) throws NoWorkTreeException, IOException, GitAPIException { boolean hasChanges = false; org.eclipse.jgit.api.Status repoStatus = new Git(repository).status().call(); hasChanges |= !repoStatus.getAdded().isEmpty(); hasChanges |= !repoStatus.getChanged().isEmpty(); hasChanges |= !repoStatus.getModified().isEmpty(); hasChanges |= !repoStatus.getRemoved().isEmpty(); hasChanges |= !repoStatus.getConflicting().isEmpty(); hasChanges |= !repoStatus.getMissing().isEmpty(); return hasChanges; }
@Override protected void executeCustom(Git git) throws Exception { StatusCommand sc = git.status(); Status status = sc.call(); if (isclean != null && status.isClean()) { PropertyHelper.getPropertyHelper(getProject()).setNewProperty(isclean, "true"); } if (isdirty != null && !status.isClean()) { PropertyHelper.getPropertyHelper(getProject()).setNewProperty(isdirty, "true"); } if (untracked != null) { ResourceCollection resources = buildResourcesCollection(status.getUntracked()); getProject().addReference(untracked, resources); } if (added != null) { ResourceCollection resources = buildResourcesCollection(status.getAdded()); getProject().addReference(added, resources); } if (modified != null) { ResourceCollection resources = buildResourcesCollection(status.getModified()); getProject().addReference(modified, resources); } if (changed != null) { ResourceCollection resources = buildResourcesCollection(status.getChanged()); getProject().addReference(changed, resources); } if (missing != null) { ResourceCollection resources = buildResourcesCollection(status.getMissing()); getProject().addReference(missing, resources); } if (removed != null) { ResourceCollection resources = buildResourcesCollection(status.getRemoved()); getProject().addReference(removed, resources); } }
/** * Gets the status of this file. * * @return status of this file. */ public TextArea getStatus() { TextArea area = null; try { Path repoPath = this.getHost().repository; Git git = Git.open(repoPath.toFile()); // // I would like to use absolutePath, but that seems to barf when // we try to relativize this if a full path is not given. // Path relativePath = repoPath.relativize(Paths.get(this.file.getPath())); Status status = git.status().addPath(relativePath.toString()).call(); if (logger.isDebugEnabled()) { logger.debug(this.file.getAbsolutePath()); logger.debug("Added: " + status.getAdded()); logger.debug("Changed: " + status.getChanged()); logger.debug("Conflicting: " + status.getConflicting()); logger.debug("Missing: " + status.getMissing()); logger.debug("Modified: " + status.getModified()); logger.debug("Removed: " + status.getRemoved()); logger.debug("Uncommitted: " + status.getUncommittedChanges()); logger.debug("Untracked: " + status.getUntracked()); logger.debug("Untracked folders; " + status.getUntrackedFolders()); } // // Are we a file or directory? // StringBuffer buffer = new StringBuffer(); int length = 0; if (this.file.isFile()) { if (status.getAdded().contains(relativePath.toString())) { buffer.append("Added" + "\n"); length++; } if (status.getChanged().contains(relativePath.toString())) { buffer.append("Changed" + "\n"); length++; } if (status.getConflicting().contains(relativePath.toString())) { buffer.append("Conflicting" + "\n"); length++; } if (status.getMissing().contains(relativePath.toString())) { buffer.append("Missing" + "\n"); length++; } if (status.getModified().contains(relativePath.toString())) { buffer.append("Modified" + "\n"); length++; } if (status.getRemoved().contains(relativePath.toString())) { buffer.append("Removed" + "\n"); length++; } if (status.getUncommittedChanges().contains(relativePath.toString())) { buffer.append("Uncommitted" + "\n"); length++; } if (status.getUntracked().contains(relativePath.toString())) { buffer.append("Untracked (New)" + "\n"); length++; } if (status.getUntrackedFolders().contains(relativePath.toString())) { buffer.append("Untracked Folders (New)" + "\n"); length++; } } else if (this.file.isDirectory()) { if (status.getUntracked().size() > 0) { buffer.append("Untracked (New)" + "\n"); length++; } if (status.getUntrackedFolders().size() > 0) { buffer.append("Untracked Folders (New)" + "\n"); length++; } } if (length > 0) { area = new TextArea(); area.setValue(buffer.toString().trim()); area.setWidth("100.0%"); area.setRows(length); area.setReadOnly(true); } } catch (IOException | NoWorkTreeException | GitAPIException e) { logger.error(e); } return area; }
private void stageMissingFilesAsDeleted(final Git git) throws GitAPIException { final Status status = git.status().call(); for (final String missingFile : status.getMissing()) { git.rm().addFilepattern(missingFile).call(); } }