List of usage examples for org.eclipse.jgit.api Git status
public StatusCommand status()
From source file:org.eclipse.emf.compare.diagram.papyrus.tests.egit.fixture.GitTestRepository.java
License:Open Source License
/** * Adds all missing or deleted files to the index. * /*from ww w. j a v a 2s . co m*/ * @throws Exception * if anything goes wrong. */ public void addDeletedFiles() throws Exception { Git git = new Git(repository); try { Status status = git.status().call(); if (!status.getMissing().isEmpty() || !status.getRemoved().isEmpty()) { RmCommand rm = git.rm(); for (String deletedFile : Iterables.concat(status.getMissing(), status.getRemoved())) { rm.addFilepattern(deletedFile); } rm.call(); } } finally { git.close(); } }
From source file:org.eclipse.emf.compare.diagram.papyrus.tests.egit.fixture.GitTestRepository.java
License:Open Source License
/** * Returns the status of this repository's files as would "git status". * /*from w ww . jav a 2 s. c o m*/ * @return * @throws Exception */ public Status status() throws Exception { Git git = new Git(repository); try { return git.status().call(); } finally { git.close(); } }
From source file:org.eclipse.emf.compare.ide.ui.tests.git.framework.internal.GitTestSupport.java
License:Open Source License
public Status getStatus() throws Exception { Git git = new Git(repository); try {//from w w w. j a va2 s . c om return git.status().call(); } finally { git.close(); } }
From source file:org.eclipse.emf.compare.ide.ui.tests.models.ModelTestCase.java
License:Open Source License
protected Status status(Repository repo) throws Exception { Git git = new Git(repo); try {/*from w w w .jav a2s . c o m*/ return git.status().call(); } finally { git.close(); } }
From source file:org.eclipse.oomph.setup.git.impl.GitCloneTaskImpl.java
License:Open Source License
private static boolean hasWorkTree(Git git) throws Exception { try {// w w w .j av a 2 s . co m StatusCommand statusCommand = git.status(); statusCommand.call(); return true; } catch (NoWorkTreeException ex) { return false; } }
From source file:org.eclipse.orion.server.git.jobs.StatusJob.java
License:Open Source License
@Override protected IStatus performJob() { Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.git"); Repository db = null;/* www. j av a 2s. co m*/ try { long t0 = System.currentTimeMillis(); Set<Entry<IPath, File>> set = GitUtils.getGitDirs(this.filePath, Traverse.GO_UP).entrySet(); File gitDir = set.iterator().next().getValue(); if (gitDir == null) { logger.error("***** Git status failed to find Git directory for request: " + this.filePath); String msg = NLS.bind("Could not find repository for {0}", filePath); return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null); } long t1 = System.currentTimeMillis(); db = FileRepositoryBuilder.create(gitDir); Git git = new Git(db); org.eclipse.jgit.api.Status gitStatus = git.status().call(); long t2 = System.currentTimeMillis(); String relativePath = GitUtils.getRelativePath(this.filePath, set.iterator().next().getKey()); IPath basePath = new Path(relativePath); org.eclipse.orion.server.git.objects.Status status = new org.eclipse.orion.server.git.objects.Status( this.baseLocation, db, gitStatus, basePath); ServerStatus result = new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, status.toJSON()); if (logger.isDebugEnabled() && (t2 - t0) > GIT_PERF_THRESHOLD) { logger.debug("Slow git status. Finding git dir: " + (t1 - t0) + "ms. JGit status call: " + (t2 - t1) + "ms"); } return result; } catch (Exception e) { String msg = NLS.bind("An error occured when generating status for ref {0}", this.filePath); return new Status(IStatus.ERROR, GitActivator.PI_GIT, msg, e); } finally { if (db != null) { // close the git repository db.close(); } } }
From source file:org.eclipse.orion.server.git.servlets.GitStatusHandlerV1.java
License:Open Source License
@Override public boolean handleRequest(HttpServletRequest request, HttpServletResponse response, String gitPathInfo) throws ServletException { try {/*from ww w .j a v a 2s .c o m*/ Path path = new Path(gitPathInfo); if (!path.hasTrailingSeparator()) { String msg = NLS.bind("Cannot get status on a file: {0}", gitPathInfo); return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null)); } Set<Entry<IPath, File>> set = GitUtils.getGitDirs(path, Traverse.GO_UP).entrySet(); File gitDir = set.iterator().next().getValue(); if (gitDir == null) return false; // TODO: or an error response code, 405? Repository db = new FileRepository(gitDir); Git git = new Git(db); Status status = git.status().call(); URI baseLocation = getURI(request); JSONObject result = new JSONObject(); result.put(GitConstants.KEY_CLONE, BaseToCloneConverter.getCloneLocation(baseLocation, BaseToCloneConverter.STATUS)); String relativePath = GitUtils.getRelativePath(path, set.iterator().next().getKey()); IPath basePath = new Path(relativePath); JSONArray children = toJSONArray(status.getAdded(), basePath, baseLocation, GitConstants.KEY_DIFF_DEFAULT); result.put(GitConstants.KEY_STATUS_ADDED, children); // TODO: bug 338913 // children = toJSONArray(diff.getAssumeUnchanged(), baseLocation, ?); // result.put(GitConstants.KEY_STATUS_ASSUME_UNCHANGED, children); children = toJSONArray(status.getChanged(), basePath, baseLocation, GitConstants.KEY_DIFF_CACHED); result.put(GitConstants.KEY_STATUS_CHANGED, children); children = toJSONArray(status.getMissing(), basePath, baseLocation, GitConstants.KEY_DIFF_DEFAULT); result.put(GitConstants.KEY_STATUS_MISSING, children); children = toJSONArray(status.getModified(), basePath, baseLocation, GitConstants.KEY_DIFF_DEFAULT); result.put(GitConstants.KEY_STATUS_MODIFIED, children); children = toJSONArray(status.getRemoved(), basePath, baseLocation, GitConstants.KEY_DIFF_CACHED); result.put(GitConstants.KEY_STATUS_REMOVED, children); children = toJSONArray(status.getUntracked(), basePath, baseLocation, GitConstants.KEY_DIFF_DEFAULT); result.put(GitConstants.KEY_STATUS_UNTRACKED, children); children = toJSONArray(status.getConflicting(), basePath, baseLocation, GitConstants.KEY_DIFF_DEFAULT); result.put(GitConstants.KEY_STATUS_CONFLICTING, children); // return repository state result.put(GitConstants.KEY_REPOSITORY_STATE, db.getRepositoryState().name()); result.put(GitConstants.KEY_INDEX, statusToIndexLocation(baseLocation)); result.put(GitConstants.KEY_COMMIT, statusToCommitLocation(baseLocation, Constants.HEAD)); OrionServlet.writeJSONResponse(request, response, result); return true; } catch (Exception e) { return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error generating status response", e)); } }
From source file:org.eclipse.osee.ote.version.git.GitVersion.java
License:Open Source License
public boolean getModified() throws IOException, NoWorkTreeException, GitAPIException { if (!file.exists()) { return false; }//from w w w. j a va2 s. co m File gitFolder = findGitDirUp(file); if (gitFolder == null) { return false; } Repository repository = buildRepository(gitFolder); Git git = new Git(repository); StatusCommand status = git.status(); String pathFilter = getPathFilterFromFullPathAndGitFolder(file, gitFolder); Status result = status.call(); Set<String> modified = result.getModified(); if (modified.contains(pathFilter)) { return true; } else { return false; } }
From source file:org.exist.git.xquery.Status.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {/* w w w. j av a 2 s . c om*/ String localPath = args[0].getStringValue(); if (!(localPath.endsWith("/"))) localPath += File.separator; Git git = Git.open(new Resource(localPath), FS); if (getName().equals(STATUS)) { MemTreeBuilder builder = getContext().getDocumentBuilder(); int nodeNr = builder.startElement(REPOSITORY, null); StatusBuilder statusBuilder = new StatusBuilder(builder); final Repository repo = git.getRepository(); diff(repo, Constants.HEAD, new FileTreeIterator(repo), statusBuilder, args[1].getStringValue(), args[2].effectiveBooleanValue()); builder.endElement(); return builder.getDocument().getNode(nodeNr); } org.eclipse.jgit.api.Status status = git.status().call(); Set<String> list; if (getName().equals(UNTRACKED)) { list = status.getUntracked(); } else if (getName().equals(ADDED)) { list = status.getAdded(); } else if (getName().equals(CHANGED)) { list = status.getChanged(); } else if (getName().equals(CONFLICTING)) { list = status.getConflicting(); } else if (getName().equals(IGNORED)) { list = status.getIgnoredNotInIndex(); } else if (getName().equals(MISSING)) { list = status.getMissing(); } else if (getName().equals(MODIFIED)) { list = status.getModified(); } else if (getName().equals(REMOVED)) { list = status.getRemoved(); } else if (getName().equals(UNTRACKED)) { list = status.getUntracked(); } else if (getName().equals(UNTRACKED_FOLDERS)) { list = status.getUntrackedFolders(); } else { return Sequence.EMPTY_SEQUENCE; } Sequence result = new ValueSequence(); for (String modified : list) { result.add(new StringValue(modified)); } return result; } catch (Throwable e) { e.printStackTrace(); throw new XPathException(this, Module.EXGIT001, e); } }
From source file:org.libx4j.maven.plugin.version.GitUtil.java
License:Open Source License
public static Set<String> lookupChangedFiles(final POMFile pomFile, final Git git) throws GitAPIException, IOException, MojoFailureException { final Status status = git.status().call(); final Set<String> changes = new HashSet<>(); changes.addAll(status.getChanged()); changes.addAll(status.getAdded());//from www.j av a2s .co m changes.addAll(status.getRemoved()); final File repoDir = git.getRepository().getDirectory().getParentFile(); final String include = pomFile.file().getParentFile().getAbsolutePath() .substring(repoDir.getAbsolutePath().length() + 1); final Iterator<String> iterator = changes.iterator(); while (iterator.hasNext()) { final String entry = iterator.next(); if (!entry.startsWith(include)) { iterator.remove(); continue; } for (final POMFile modulePomFile : pomFile.modules()) { final String exclude = modulePomFile.file().getParentFile().getAbsolutePath() .substring(repoDir.getAbsolutePath().length() + 1); if (entry.startsWith(exclude)) { iterator.remove(); break; } } } return changes; }