List of usage examples for org.eclipse.jgit.lib Repository getRepositoryState
@NonNull
public RepositoryState getRepositoryState()
From source file:org.eclipse.emf.compare.egit.ui.internal.merge.ModelGitMergeEditorInput.java
License:Open Source License
private RevCommit getRightCommit(RevWalk revWalk, Repository repository) throws InvocationTargetException { try {// w w w . jav a 2 s . c om String target; if (repository.getRepositoryState().equals(RepositoryState.MERGING)) { target = Constants.MERGE_HEAD; } else if (repository.getRepositoryState().equals(RepositoryState.CHERRY_PICKING)) { target = Constants.CHERRY_PICK_HEAD; } else if (repository.getRepositoryState().equals(RepositoryState.REBASING_INTERACTIVE)) { target = readFile(repository.getDirectory(), RebaseCommand.REBASE_MERGE + File.separatorChar + RebaseCommand.STOPPED_SHA); } else { target = Constants.ORIG_HEAD; } ObjectId mergeHead = repository.resolve(target); if (mergeHead == null) { throw new IOException(NLS.bind(UIText.ValidationUtils_CanNotResolveRefMessage, target)); } return revWalk.parseCommit(mergeHead); } catch (IOException e) { throw new InvocationTargetException(e); } }
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 www .j a v a 2 s.c om 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.flowerplatform.web.git.history.remote.GitHistoryStatefulService.java
License:Open Source License
private String mergeStatus(Repository repository) { String message = null;/*from w w w . j av a 2 s . com*/ try { Ref head = repository.getRef(Constants.HEAD); if (head == null || !head.isSymbolic()) { message = GitPlugin.getInstance().getMessage("git.merge.headIsNoBranch"); } else if (!repository.getRepositoryState().equals(RepositoryState.SAFE)) message = GitPlugin.getInstance().getMessage("git.merge.wrongRepositoryState", repository.getRepositoryState()); } catch (IOException e) { message = e.getMessage(); } return message; }