List of usage examples for org.eclipse.jgit.lib Repository shortenRefName
@NonNull public static String shortenRefName(String refName)
From source file:org.eclipse.orion.server.git.objects.RemoteBranch.java
License:Open Source License
private String getName(boolean fullName, boolean encode) { String name = Constants.R_REMOTES + remote.getName() + "/" + this.name; //$NON-NLS-1$ if (!fullName) name = Repository.shortenRefName(name); if (encode)//w w w .j a va 2 s .c o m name = GitUtils.encode(name); return name; }
From source file:org.eclipse.orion.server.git.objects.Tag.java
License:Open Source License
private String getName(boolean fullName, boolean encode) { String name = null;/*ww w .j av a 2 s .c o m*/ if (tag != null) name = fullName ? Constants.R_TAGS + tag.getTagName() : tag.getTagName(); if (ref != null) name = fullName ? ref.getName() : Repository.shortenRefName(ref.getName()); if (name == null) return null; if (encode) name = GitUtils.encode(name); return name; }
From source file:org.eclipse.orion.server.git.servlets.GitBranchHandlerV1.java
License:Open Source License
private boolean handleGet(HttpServletRequest request, HttpServletResponse response, String path) throws IOException, JSONException, ServletException, URISyntaxException, CoreException { // FIXME: what if there is a branch named "file"? Path p = new Path(path); if (p.segment(0).equals("file")) { //$NON-NLS-1$ // branch list: expected path /git/branch/file/{path} File gitDir = GitUtils.getGitDir(p); Repository db = new FileRepository(gitDir); Git git = new Git(db); List<Ref> branches = git.branchList().call(); JSONObject result = new JSONObject(); JSONArray children = new JSONArray(); for (Ref ref : branches) { JSONObject child = BranchToJSONConverter.toJSON(ref, db, getURI(request), 2); children.put(child);//from w ww. jav a 2 s . c om } result.put(ProtocolConstants.KEY_CHILDREN, children); OrionServlet.writeJSONResponse(request, response, result); return true; } else if (p.segment(1).equals("file")) { //$NON-NLS-1$ // branch details: expected path /git/branch/{name}/file/{path} File gitDir = GitUtils.getGitDir(p.removeFirstSegments(1)); Repository db = new FileRepository(gitDir); Git git = new Git(db); List<Ref> branches = git.branchList().call(); JSONObject result = null; for (Ref ref : branches) { if (Repository.shortenRefName(ref.getName()).equals(p.segment(0))) { result = BranchToJSONConverter.toJSON(ref, db, getURI(request), 3); break; } } if (result == null) { String msg = NLS.bind("Branch {0} not found", p.segment(0)); //$NON-NLS-1$ return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, msg, null)); } OrionServlet.writeJSONResponse(request, response, result); return true; } return false; }
From source file:org.eclipse.orion.server.git.servlets.GitBranchHandlerV1.java
License:Open Source License
private boolean handlePost(HttpServletRequest request, HttpServletResponse response, String path) throws IOException, JSONException, ServletException, URISyntaxException, CoreException, JGitInternalException, GitAPIException { Path p = new Path(path); // expected path /gitapi/branch/file/{path} if (p.segment(0).equals("file")) { //$NON-NLS-1$ JSONObject toCreate = OrionServlet.readJSONRequest(request); String branchName = toCreate.optString(ProtocolConstants.KEY_NAME, null); String startPoint = toCreate.optString(GitConstants.KEY_BRANCH_NAME, null); if (branchName == null || branchName.isEmpty()) { if (startPoint == null || startPoint.isEmpty()) return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Branch name must be provided", null)); else { String shortName = Repository.shortenRefName(startPoint); branchName = shortName.substring(shortName.lastIndexOf("/") + 1); //$NON-NLS-1$ }//w w w . j ava 2 s. c o m } File gitDir = GitUtils.getGitDir(p); Repository db = new FileRepository(gitDir); Git git = new Git(db); CreateBranchCommand cc = git.branchCreate(); cc.setName(branchName); if (startPoint != null && !startPoint.isEmpty()) { cc.setStartPoint(startPoint); cc.setUpstreamMode(SetupUpstreamMode.TRACK); } Ref ref = cc.call(); // TODO: what if something went wrong, handle exception JSONObject result = BranchToJSONConverter.toJSON(ref, db, getURI(request), 2); OrionServlet.writeJSONResponse(request, response, result); response.setHeader(ProtocolConstants.HEADER_LOCATION, result.getString(ProtocolConstants.KEY_LOCATION)); response.setStatus(HttpServletResponse.SC_CREATED); return true; } String msg = NLS.bind("Failed to create a branch for {0}", path); //$NON-NLS-1$ return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null)); }
From source file:org.eclipse.orion.server.git.servlets.GitCommitHandlerV1.java
License:Open Source License
private boolean handleGetCommitLog(HttpServletRequest request, HttpServletResponse response, Repository db, String refIdsRange, String path) throws AmbiguousObjectException, IOException, ServletException, JSONException, URISyntaxException, CoreException { int page = request.getParameter("page") != null ? new Integer(request.getParameter("page")).intValue() : 0; //$NON-NLS-1$ //$NON-NLS-2$ int pageSize = request.getParameter("pageSize") != null //$NON-NLS-1$ ? new Integer(request.getParameter("pageSize")).intValue() //$NON-NLS-1$ : PAGE_SIZE;//from w w w .java 2 s . c o m ObjectId toObjectId = null; ObjectId fromObjectId = null; Ref toRefId = null; Ref fromRefId = null; Git git = new Git(db); LogCommand log = git.log(); if (refIdsRange != null) { // git log <since>..<until> if (refIdsRange.contains("..")) { //$NON-NLS-1$ String[] commits = refIdsRange.split("\\.\\."); //$NON-NLS-1$ if (commits.length != 2) { String msg = NLS.bind("Failed to generate commit log for ref {0}", refIdsRange); return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null)); } fromObjectId = db.resolve(commits[0]); fromRefId = db.getRef(commits[0]); if (fromObjectId == null) { String msg = NLS.bind("Failed to generate commit log for ref {0}", commits[0]); return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null)); } toObjectId = db.resolve(commits[1]); toRefId = db.getRef(commits[1]); if (toObjectId == null) { String msg = NLS.bind("No ref or commit found: {0}", commits[1]); return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, msg, null)); } } else { toObjectId = db.resolve(refIdsRange); toRefId = db.getRef(refIdsRange); if (toObjectId == null) { String msg = NLS.bind("No ref or commit found: {0}", refIdsRange); return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, msg, null)); } } // set the commit range log.add(toObjectId); if (fromObjectId != null) log.not(fromObjectId); } else { // git log --all // workaround for git log --all - see bug 353310 List<Ref> branches = git.branchList().setListMode(ListMode.ALL).call(); for (Ref branch : branches) { log.add(branch.getObjectId()); } } // set the path filter TreeFilter filter = null; boolean isRoot = true; if (path != null && !"".equals(path)) { //$NON-NLS-1$ filter = AndTreeFilter.create(PathFilterGroup.createFromStrings(Collections.singleton(path)), TreeFilter.ANY_DIFF); log.addPath(path); isRoot = false; } try { Iterable<RevCommit> commits = log.call(); Map<ObjectId, JSONArray> commitToBranchMap = getCommitToBranchMap(db); JSONObject result = toJSON(db, OrionServlet.getURI(request), commits, commitToBranchMap, page, pageSize, filter, isRoot); result.put(GitConstants.KEY_REPOSITORY_PATH, isRoot ? "" : path); //$NON-NLS-1$ if (refIdsRange == null) result.put(GitConstants.KEY_CLONE, BaseToCloneConverter.getCloneLocation(getURI(request), BaseToCloneConverter.COMMIT)); else result.put(GitConstants.KEY_CLONE, BaseToCloneConverter.getCloneLocation(getURI(request), BaseToCloneConverter.COMMIT_REFRANGE)); if (toRefId != null) { result.put(GitConstants.KEY_REMOTE, BaseToRemoteConverter.getRemoteBranchLocation(getURI(request), Repository.shortenRefName(toRefId.getName()), db, BaseToRemoteConverter.REMOVE_FIRST_3)); String refTargetName = toRefId.getTarget().getName(); if (refTargetName.startsWith(Constants.R_HEADS)) { // this is a branch result.put(GitConstants.KEY_LOG_TO_REF, BranchToJSONConverter.toJSON(toRefId.getTarget(), db, getURI(request), 3)); } } if (fromRefId != null) { String refTargetName = fromRefId.getTarget().getName(); if (refTargetName.startsWith(Constants.R_HEADS)) { // this is a branch result.put(GitConstants.KEY_LOG_FROM_REF, BranchToJSONConverter.toJSON(fromRefId.getTarget(), db, getURI(request), 3)); } } OrionServlet.writeJSONResponse(request, response, result); return true; } catch (NoHeadException e) { String msg = NLS.bind("No HEAD reference found when generating log for ref {0}", refIdsRange); return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e)); } catch (JGitInternalException e) { String msg = NLS.bind("An internal error occured when generating log for ref {0}", refIdsRange); return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e)); } }
From source file:org.eclipse.orion.server.git.servlets.GitRemoteHandlerV1.java
License:Open Source License
private boolean handleGet(HttpServletRequest request, HttpServletResponse response, String path) throws IOException, JSONException, ServletException, URISyntaxException, CoreException { Path p = new Path(path); // FIXME: what if a remote or branch is named "file"? if (p.segment(0).equals("file")) { //$NON-NLS-1$ // /git/remote/file/{path} File gitDir = GitUtils.getGitDir(p); Repository db = new FileRepository(gitDir); Set<String> configNames = db.getConfig().getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION); JSONObject result = new JSONObject(); JSONArray children = new JSONArray(); URI baseLocation = getURI(request); for (String configName : configNames) { JSONObject o = new JSONObject(); o.put(ProtocolConstants.KEY_NAME, configName); o.put(ProtocolConstants.KEY_TYPE, GitConstants.KEY_REMOTE_NAME); o.put(GitConstants.KEY_URL, db.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, configName, "url" /*RemoteConfig.KEY_URL*/)); String pushUrl = null; if ((pushUrl = db.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION, configName, "pushurl" /*RemoteConfig.KEY_PUSHURL*/)) != null) o.put(GitConstants.KEY_PUSH_URL, pushUrl); o.put(ProtocolConstants.KEY_LOCATION, BaseToRemoteConverter.REMOVE_FIRST_2 .baseToRemoteLocation(baseLocation, configName, "" /* no branch name */)); //$NON-NLS-1$ children.put(o);//from ww w . jav a 2 s.c om } result.put(ProtocolConstants.KEY_CHILDREN, children); OrionServlet.writeJSONResponse(request, response, result); return true; } else if (p.segment(1).equals("file")) { //$NON-NLS-1$ // /git/remote/{remote}/file/{path} File gitDir = GitUtils.getGitDir(p.removeFirstSegments(1)); Repository db = new FileRepository(gitDir); Set<String> configNames = db.getConfig().getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION); JSONObject result = new JSONObject(); URI baseLocation = getURI(request); for (String configName : configNames) { if (configName.equals(p.segment(0))) { result.put(ProtocolConstants.KEY_NAME, configName); result.put(ProtocolConstants.KEY_TYPE, GitConstants.KEY_REMOTE_NAME); result.put(ProtocolConstants.KEY_LOCATION, BaseToRemoteConverter.REMOVE_FIRST_3 .baseToRemoteLocation(baseLocation, p.segment(0), "" /* no branch name */)); //$NON-NLS-1$ JSONArray children = new JSONArray(); List<Ref> refs = new ArrayList<Ref>(); for (Entry<String, Ref> refEntry : db.getRefDatabase() .getRefs(Constants.R_REMOTES + p.uptoSegment(1)).entrySet()) { if (!refEntry.getValue().isSymbolic()) { Ref ref = refEntry.getValue(); String name = ref.getName(); name = Repository.shortenRefName(name) .substring(Constants.DEFAULT_REMOTE_NAME.length() + 1); if (db.getBranch().equals(name)) { refs.add(0, ref); } else { refs.add(ref); } } } for (Ref ref : refs) { JSONObject o = new JSONObject(); String name = ref.getName(); o.put(ProtocolConstants.KEY_NAME, name.substring(Constants.R_REMOTES.length())); o.put(ProtocolConstants.KEY_FULL_NAME, name); o.put(ProtocolConstants.KEY_TYPE, GitConstants.REMOTE_TRACKING_BRANCH_TYPE); o.put(ProtocolConstants.KEY_ID, ref.getObjectId().name()); // see bug 342602 // o.put(GitConstants.KEY_COMMIT, baseToCommitLocation(baseLocation, name)); o.put(ProtocolConstants.KEY_LOCATION, BaseToRemoteConverter.REMOVE_FIRST_3.baseToRemoteLocation(baseLocation, "" /*short name is {remote}/{branch}*/, Repository.shortenRefName(name))); //$NON-NLS-1$ o.put(GitConstants.KEY_COMMIT, BaseToCommitConverter.getCommitLocation(baseLocation, ref.getObjectId().name(), BaseToCommitConverter.REMOVE_FIRST_3)); o.put(GitConstants.KEY_HEAD, BaseToCommitConverter.getCommitLocation(baseLocation, Constants.HEAD, BaseToCommitConverter.REMOVE_FIRST_3)); o.put(GitConstants.KEY_CLONE, BaseToCloneConverter.getCloneLocation(baseLocation, BaseToCloneConverter.REMOTE)); o.put(GitConstants.KEY_BRANCH, BaseToBranchConverter.getBranchLocation(baseLocation, BaseToBranchConverter.REMOTE)); o.put(GitConstants.KEY_INDEX, BaseToIndexConverter.getIndexLocation(baseLocation, BaseToIndexConverter.REMOTE)); children.put(o); } result.put(ProtocolConstants.KEY_CHILDREN, children); OrionServlet.writeJSONResponse(request, response, result); return true; } } String msg = NLS.bind("Couldn't find remote : {0}", p.segment(0)); return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, msg, null)); } else if (p.segment(2).equals("file")) { //$NON-NLS-1$ // /git/remote/{remote}/{branch}/file/{path} File gitDir = GitUtils.getGitDir(p.removeFirstSegments(2)); Repository db = new FileRepository(gitDir); Set<String> configNames = db.getConfig().getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION); URI baseLocation = getURI(request); for (String configName : configNames) { if (configName.equals(p.segment(0))) { for (Entry<String, Ref> refEntry : db.getRefDatabase().getRefs(Constants.R_REMOTES) .entrySet()) { Ref ref = refEntry.getValue(); String name = ref.getName(); if (!ref.isSymbolic() && name.equals(Constants.R_REMOTES + p.uptoSegment(2).removeTrailingSeparator())) { JSONObject result = new JSONObject(); result.put(ProtocolConstants.KEY_NAME, name.substring(Constants.R_REMOTES.length())); result.put(ProtocolConstants.KEY_FULL_NAME, name); result.put(ProtocolConstants.KEY_TYPE, GitConstants.REMOTE_TRACKING_BRANCH_TYPE); result.put(ProtocolConstants.KEY_ID, ref.getObjectId().name()); // see bug 342602 // result.put(GitConstants.KEY_COMMIT, baseToCommitLocation(baseLocation, name)); result.put(ProtocolConstants.KEY_LOCATION, BaseToRemoteConverter.REMOVE_FIRST_4.baseToRemoteLocation(baseLocation, "" /*short name is {remote}/{branch}*/, //$NON-NLS-1$ Repository.shortenRefName(name))); result.put(GitConstants.KEY_COMMIT, BaseToCommitConverter.getCommitLocation( baseLocation, ref.getObjectId().name(), BaseToCommitConverter.REMOVE_FIRST_4)); result.put(GitConstants.KEY_HEAD, BaseToCommitConverter.getCommitLocation(baseLocation, Constants.HEAD, BaseToCommitConverter.REMOVE_FIRST_4)); result.put(GitConstants.KEY_CLONE, BaseToCloneConverter.getCloneLocation(baseLocation, BaseToCloneConverter.REMOTE_BRANCH)); OrionServlet.writeJSONResponse(request, response, result); return true; } } } } JSONObject errorData = new JSONObject(); errorData.put(GitConstants.KEY_CLONE, BaseToCloneConverter.getCloneLocation(baseLocation, BaseToCloneConverter.REMOTE_BRANCH)); return statusHandler .handleRequest(request, response, new ServerStatus( new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE, "No remote branch found: " + p.uptoSegment(2).removeTrailingSeparator()), HttpServletResponse.SC_NOT_FOUND, errorData)); } return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Bad request, \"/git/remote/{remote}/{branch}/file/{path}\" expected", null)); }
From source file:org.eclipse.orion.server.git.servlets.GitRemoteHandlerV1.java
License:Open Source License
private JSONObject toJSON(String remoteName, URI baseLocation) throws JSONException, URISyntaxException { JSONObject result = new JSONObject(); result.put(ProtocolConstants.KEY_LOCATION, BaseToRemoteConverter.REMOVE_FIRST_2 .baseToRemoteLocation(baseLocation, Repository.shortenRefName(remoteName), "")); return result; }
From source file:org.eclipse.orion.server.git.servlets.GitTreeHandlerV1.java
License:Open Source License
@Override protected boolean handleGet(RequestInfo requestInfo) throws ServletException { HttpServletRequest request = requestInfo.request; HttpServletResponse response = requestInfo.response; String gitSegment = requestInfo.gitSegment; Repository repo = requestInfo.db;/* w ww . j a va 2s .co m*/ String pattern = requestInfo.relativePath; IPath filePath = requestInfo.filePath; String meta = request.getParameter("parts"); //$NON-NLS-1$ RevWalk walk = null; TreeWalk treeWalk = null; IPath filterPath = new Path(pattern); try { if (filterPath.segmentCount() == 0) { JSONArray children = new JSONArray(); URI baseLocation = getURI(request); List<Ref> call = new Git(repo).branchList().setListMode(ListMode.ALL).call(); for (Ref ref : call) { String branchName = Repository.shortenRefName(ref.getName()); JSONObject branch = listEntry(branchName, 0, true, 0, baseLocation, GitUtils.encode(branchName)); children.put(branch); } JSONObject result = listEntry(filePath.segment(0), 0, true, 0, baseLocation, null); result.put(ProtocolConstants.KEY_CHILDREN, children); OrionServlet.writeJSONResponse(request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT); return true; } gitSegment = GitUtils.decode(filterPath.segment(0)); filterPath = filterPath.removeFirstSegments(1); pattern = filterPath.toPortableString(); ObjectId head = repo.resolve(gitSegment); if (head == null) { throw new Exception("Missing ref in git segment"); } walk = new RevWalk(repo); // add try catch to catch failures RevCommit commit = walk.parseCommit(head); RevTree tree = commit.getTree(); treeWalk = new TreeWalk(repo); treeWalk.addTree(tree); treeWalk.setRecursive(false); if (!pattern.equals("")) { //$NON-NLS-1$ PathFilter pathFilter = PathFilter.create(pattern); treeWalk.setFilter(pathFilter); } JSONArray contents = new JSONArray(); JSONObject result = null; ArrayList<JSONObject> parents = new ArrayList<JSONObject>(); URI baseLocation = ServletResourceHandler.getURI(request); Path basePath = new Path(baseLocation.getPath()); IPath tmp = new Path("/"); //$NON-NLS-1$ for (int i = 0; i < 5; i++) { tmp = tmp.append(basePath.segment(i)); } URI cloneLocation = new URI(baseLocation.getScheme(), baseLocation.getAuthority(), tmp.toPortableString(), null, baseLocation.getFragment()); JSONObject ref = listEntry(gitSegment, 0, true, 0, cloneLocation, GitUtils.encode(gitSegment)); parents.add(ref); parents.add( listEntry(new Path(cloneLocation.getPath()).lastSegment(), 0, true, 0, cloneLocation, null)); URI locationWalk = URIUtil.append(cloneLocation, GitUtils.encode(gitSegment)); while (treeWalk.next()) { if (treeWalk.isSubtree()) { if (treeWalk.getPathLength() > pattern.length()) { String name = treeWalk.getNameString(); contents.put(listEntry(name, 0, true, 0, locationWalk, name)); } if (treeWalk.getPathLength() <= pattern.length()) { locationWalk = URIUtil.append(locationWalk, treeWalk.getNameString()); parents.add(0, listEntry(treeWalk.getNameString(), 0, true, 0, locationWalk, null)); treeWalk.enterSubtree(); } } else { ObjectId objId = treeWalk.getObjectId(0); ObjectLoader loader = repo.open(objId); long size = loader.getSize(); if (treeWalk.getPathLength() == pattern.length()) { if ("meta".equals(meta)) { //$NON-NLS-1$ result = listEntry(treeWalk.getNameString(), 0, false, 0, locationWalk, treeWalk.getNameString()); } else { return getFileContents(request, response, repo, treeWalk, tree); } } else { String name = treeWalk.getNameString(); contents.put(listEntry(name, 0, false, size, locationWalk, name)); } } } if (result == null) { result = parents.remove(0); result.put("Children", contents); //$NON-NLS-1$ } result.put("Parents", new JSONArray(parents)); //$NON-NLS-1$ response.setContentType("application/json"); //$NON-NLS-1$ response.setHeader("Cache-Control", "no-cache"); //$NON-NLS-1$ response.setHeader("ETag", "\"" + tree.getId().getName() + "\""); //$NON-NLS-1$ OrionServlet.writeJSONResponse(request, response, result); return true; } catch (Exception e) { return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when requesting commit info.", e)); } finally { if (walk != null) walk.release(); if (treeWalk != null) treeWalk.release(); } }
From source file:org.eclipse.orion.server.git.servlets.PushJob.java
License:Open Source License
private IStatus doPush() throws IOException, CoreException, JGitInternalException, InvalidRemoteException, URISyntaxException, JSONException { // /git/remote/{remote}/{branch}/file/{path} File gitDir = GitUtils.getGitDir(path.removeFirstSegments(2)); Repository db = new FileRepository(gitDir); Git git = new Git(db); PushCommand pushCommand = git.push(); RemoteConfig remoteConfig = new RemoteConfig(git.getRepository().getConfig(), path.segment(0)); credentials.setUri(remoteConfig.getURIs().get(0)); pushCommand.setCredentialsProvider(credentials); // ObjectId ref = db.resolve(srcRef); RefSpec spec = new RefSpec(srcRef + ":" + Constants.R_HEADS + path.segment(1)); //$NON-NLS-1$ pushCommand.setRemote(path.segment(0)).setRefSpecs(spec); if (tags)/*from w w w . j a v a 2 s .c o m*/ pushCommand.setPushTags(); pushCommand.setForce(force); Iterable<PushResult> resultIterable = pushCommand.call(); PushResult pushResult = resultIterable.iterator().next(); // this set will contain only OK status or UP_TO_DATE status Set<RemoteRefUpdate.Status> statusSet = new HashSet<RemoteRefUpdate.Status>(); for (final RemoteRefUpdate rru : pushResult.getRemoteUpdates()) { final String rm = rru.getRemoteName(); // final String sr = rru.isDelete() ? null : rru.getSrcRef(); // check status only for branch given in the URL or tags if (path.segment(1).equals(Repository.shortenRefName(rm)) || rm.startsWith(Constants.R_TAGS)) { RemoteRefUpdate.Status status = rru.getStatus(); // any status different from UP_TO_DATE and OK should generate warning if (status != RemoteRefUpdate.Status.OK && status != RemoteRefUpdate.Status.UP_TO_DATE) return new Status(IStatus.WARNING, GitActivator.PI_GIT, status.name()); // add OK or UP_TO_DATE status to the set statusSet.add(status); } // TODO: return results for all updated branches once push is available for remote, see bug 342727, comment 1 } if (statusSet.contains(RemoteRefUpdate.Status.OK)) // if there is OK status in the set -> something was updated return Status.OK_STATUS; else // if there is no OK status in the set -> only UP_TO_DATE status is possible return new Status(IStatus.WARNING, GitActivator.PI_GIT, RemoteRefUpdate.Status.UP_TO_DATE.name()); }
From source file:org.fedoraproject.eclipse.packager.git.FpGitProjectBits.java
License:Open Source License
/** * Parse available branch names from Git remote branches. * //from w w w . j a v a 2 s . c o m * @return */ private HashMap<String, String> getBranches() { HashMap<String, String> branches = new HashMap<String, String>(); try { Map<String, Ref> remotes = git.getRepository().getRefDatabase().getRefs(Constants.R_REMOTES); Set<String> keyset = remotes.keySet(); String branch; for (String key : keyset) { // use shortenRefName() to get rid of refs/*/ prefix branch = Repository.shortenRefName(remotes.get(key).getName()); branch = mapBranchName(branch); // do the branch name mapping if (branch != null) { branches.put(branch, branch); } } } catch (IOException ioException) { ioException.printStackTrace(); } return branches; }