Java源码示例:org.eclipse.jgit.api.ListBranchCommand.ListMode

示例1
@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;
}
 
示例2
/**
 * 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;
}
 
示例3
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));
	}
}
 
示例4
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;
}
 
示例5
@Override
public List<String> getBranches() {
  return getBranches( ListMode.ALL );
}
 
示例6
@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;
   }
 
示例7
private boolean isBranch(Git git, String label) throws GitAPIException {
	return containsBranch(git, label, ListMode.ALL);
}
 
示例8
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());

	}