org.eclipse.jgit.api.ListBranchCommand.ListMode Java Examples
The following examples show how to use
org.eclipse.jgit.api.ListBranchCommand.ListMode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JGitOperator.java From verigreen with Apache License 2.0 | 6 votes |
@Override public List<String> retreiveBranches() { List <String> receivedListAsString = new ArrayList<>(); List <Ref> receivedList; try { receivedList = _git.branchList().setListMode(ListMode.ALL).call(); for (Ref ref : receivedList) { receivedListAsString.add(ref.getName()); } } catch (GitAPIException e) { VerigreenLogger.get().log( getClass().getName(), RuntimeUtils.getCurrentMethodName(), "Failed to receive branches list"); return null; } return receivedListAsString; }
Example #2
Source File: UIGit.java From hop with Apache License 2.0 | 5 votes |
/** * Get a list of branches based on mode * @param mode * @return */ private List<String> getBranches( ListMode mode ) { try { return git.branchList().setListMode( mode ).call().stream() .filter( ref -> !ref.getName().endsWith( Constants.HEAD ) ) .map( ref -> Repository.shortenRefName( ref.getName() ) ) .collect( Collectors.toList() ); } catch ( Exception e ) { e.printStackTrace(); } return null; }
Example #3
Source File: GitRepositoryExampleService.java From statecharts with Eclipse Public License 1.0 | 5 votes |
private boolean doesBranchExist(Git git, BranchType type, String remoteBranch) throws GitAPIException { if (type == GitRepositoryExampleService.BranchType.LOCAL) { return git.branchList().setListMode(ListMode.ALL).call().stream() .anyMatch(branch -> branch.getName().equals("refs/heads/" + remoteBranch)); } else { return git.branchList().setListMode(ListMode.REMOTE).call().stream() .anyMatch(branch -> branch.getName().equals("refs/remotes/origin/" + remoteBranch)); } }
Example #4
Source File: JGitEnvironmentRepository.java From spring-cloud-config with Apache License 2.0 | 5 votes |
private boolean containsBranch(Git git, String label, ListMode listMode) throws GitAPIException { ListBranchCommand command = git.branchList(); if (listMode != null) { command.setListMode(listMode); } List<Ref> branches = command.call(); for (Ref ref : branches) { if (ref.getName().endsWith("/" + label)) { return true; } } return false; }
Example #5
Source File: UIGit.java From hop with Apache License 2.0 | 4 votes |
@Override public List<String> getBranches() { return getBranches( ListMode.ALL ); }
Example #6
Source File: JGitOperator.java From verigreen with Apache License 2.0 | 4 votes |
@Override public boolean push(String sourceBranch, String destinationBranch) { PushCommand command = _git.push(); boolean ret = true; RefSpec refSpec = new RefSpec().setSourceDestination(sourceBranch, destinationBranch); command.setRefSpecs(refSpec); try { List<Ref> remoteBranches = _git.branchList().setListMode(ListMode.REMOTE).call(); if(_cp != null) command.setCredentialsProvider(_cp); Iterable<PushResult> results = command.call(); for (PushResult pushResult : results) { Collection<RemoteRefUpdate> resultsCollection = pushResult.getRemoteUpdates(); Map<PushResult,RemoteRefUpdate> resultsMap = new HashMap<>(); for(RemoteRefUpdate remoteRefUpdate : resultsCollection) { resultsMap.put(pushResult, remoteRefUpdate); } RemoteRefUpdate remoteUpdate = pushResult.getRemoteUpdate(destinationBranch); if (remoteUpdate != null) { org.eclipse.jgit.transport.RemoteRefUpdate.Status status = remoteUpdate.getStatus(); ret = status.equals(org.eclipse.jgit.transport.RemoteRefUpdate.Status.OK) || status.equals(org.eclipse.jgit.transport.RemoteRefUpdate.Status.UP_TO_DATE); } if(remoteUpdate == null && !remoteBranches.toString().contains(destinationBranch)) { for(RemoteRefUpdate resultValue : resultsMap.values()) { if(resultValue.toString().contains("REJECTED_OTHER_REASON")) { ret = false; } } } } } catch (Throwable e) { throw new RuntimeException(String.format( "Failed to push [%s] into [%s]", sourceBranch, destinationBranch), e); } return ret; }
Example #7
Source File: JGitEnvironmentRepository.java From spring-cloud-config with Apache License 2.0 | 4 votes |
private boolean isBranch(Git git, String label) throws GitAPIException { return containsBranch(git, label, ListMode.ALL); }
Example #8
Source File: ChurnRateCalculator.java From scava with Eclipse Public License 2.0 | 3 votes |
public void setRemoteBranches() throws GitAPIException { List<Ref> call = repo.branchList().setListMode(ListMode.REMOTE).call(); for (Ref ref : call) { System.out.println("Remote Branches: " + ref + " " + ref.getName() + " " + ref.getName().substring(ref.getName().lastIndexOf("/") + 1)); remoteBranches.add(ref.getName()); } System.out.println("Total remote branches" + " " + remoteBranches.size()); }