Java 类org.eclipse.jgit.api.ListBranchCommand.ListMode 实例源码

项目:gmds    文件:Branches.java   
public static void main(String[] args) throws IOException, GitAPIException {
        Repository repo = Commands.getRepo(Consts.META_REPO_PATH);

        Git git = new Git(repo);

        // Create a new branch
        git.branchCreate().setName("newBranch").call();
// Checkout the new branch
        git.checkout().setName("newBranch").call();
        // List the existing branches
        List<Ref> listRefsBranches = git.branchList().setListMode(ListMode.ALL).call();
        listRefsBranches.forEach((refBranch) -> {
            System.out.println("Branch : " + refBranch.getName());
        });
// Go back on "master" branch and remove the created one
        git.checkout().setName("master");
        git.branchDelete().setBranchNames("newBranch");
    }
项目:verigreen    文件:JGitOperator.java   
@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;
}
项目:pdi-git-plugin    文件:UIGit.java   
/**
 * 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;
}
项目:Black    文件:test.java   
public static Ref getBranch(String repositoryPath,ObjectId id) throws IOException, GitAPIException{
    Git git = new Git(new FileRepository(repositoryPath+"/.git"));
    ListBranchCommand list = git.branchList().setListMode(ListMode.ALL);
    List<Ref> call = list.call();
    Ref ref = null;
    for(Ref r:call){
        if(r.getObjectId().equals(id)){
            ref = r;
        }
    }
    return ref;
}
项目:Black    文件:test.java   
public void cloneAll(String host) throws InvalidRemoteException, TransportException, GitAPIException{
    Git git = Git.cloneRepository().setURI(host).setNoCheckout(true).setCloneAllBranches(true).call();
    List<Ref> branches = git.branchList().setListMode( ListMode.REMOTE ).call();
    for(Ref r:branches){
        System.out.println(r.getName());
    }
}
项目:Camel    文件:GitProducer.java   
protected void doShowBranches(Exchange exchange, String operation) throws Exception {
    List<Ref> result = null;
    try {
        result = git.branchList().setListMode(ListMode.ALL).call();
    } catch (Exception e) {
        LOG.error("There was an error in Git " + operation + " operation");
        throw e;
    }
    exchange.getOut().setBody(result);
}
项目:che    文件:JGitConnection.java   
private Revision getRevision(RevCommit commit, String filePath)
    throws GitAPIException, IOException {
  List<String> commitParentsList =
      Stream.of(commit.getParents()).map(RevCommit::getName).collect(Collectors.toList());

  return newDto(Revision.class)
      .withId(commit.getId().getName())
      .withMessage(commit.getFullMessage())
      .withCommitTime((long) commit.getCommitTime() * 1000)
      .withCommitter(getCommitCommitter(commit))
      .withAuthor(getCommitAuthor(commit))
      .withBranches(getBranchesOfCommit(commit, ListMode.ALL))
      .withCommitParent(commitParentsList)
      .withDiffCommitFile(getCommitDiffFiles(commit, filePath));
}
项目:che    文件:JGitConnection.java   
private List<Branch> getBranchesOfCommit(RevCommit commit, ListMode mode) throws GitAPIException {
  List<Ref> branches =
      getGit().branchList().setListMode(mode).setContains(commit.getName()).call();
  return branches
      .stream()
      .map(branch -> newDto(Branch.class).withName(branch.getName()))
      .collect(toList());
}
项目:compiler    文件:GitConnector.java   
@Override
public void getBranches(final List<String> names, final List<String> commits) {
    try {
        for (final Ref ref : git.branchList().setListMode(ListMode.REMOTE).call()) {
            names.add(ref.getName());
            commits.add(ref.getObjectId().getName());
        }
    } catch (final GitAPIException e) {
        if (debug)
            System.err.println("Git Error reading branches: " + e.getMessage());
    }
}
项目:spring-cloud-config    文件:JGitEnvironmentRepository.java   
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;
}
项目:git-server    文件:JGitRepositoryFacade.java   
@Override
public Collection<BranchModel> getBranches() {
    try {
        return git.branchList()
            .setListMode(ListMode.ALL)
            .call().stream()
            .map(this::transformToBranchModel)
            .collect(Collectors.toList());
    }
    catch (GitAPIException e) {
        throw new GitException(e.getMessage(), e);
    }
}
项目:systemdesign    文件:GitVersionControl.java   
@Override
public Stream<VersionInfo> getBranches() throws IOException {
    try {
        return refToVersionInfo(repo.branchList().setListMode(ListMode.ALL).call().stream());
    } catch (GitAPIException ex) {
        throw new IOException(ex);
    }
}
项目:systemdesign    文件:GitVersionControl.java   
@Override
public Optional<VersionInfo> getDefaultBaseline() {
    try {
        return refToVersionInfo(
                repo.branchList()
                .setListMode(ListMode.ALL)
                .setContains("HEAD")
                .call()
                .stream()).findAny();
    } catch (GitAPIException ex) {
        return Optional.empty();
    }
}
项目:pdi-git-plugin    文件:UIGit.java   
@Override
public List<String> getBranches() {
  return getBranches( ListMode.ALL );
}
项目:che    文件:JGitConnection.java   
@Override
public List<Branch> branchList(BranchListMode listMode) throws GitException {
  ListBranchCommand listBranchCommand = getGit().branchList();
  if (LIST_ALL == listMode || listMode == null) {
    listBranchCommand.setListMode(ListMode.ALL);
  } else if (LIST_REMOTE == listMode) {
    listBranchCommand.setListMode(ListMode.REMOTE);
  }
  List<Ref> refs;
  String currentRef;
  try {
    refs = listBranchCommand.call();
    String headBranch = getRepository().getBranch();
    Optional<Ref> currentTag =
        getGit()
            .tagList()
            .call()
            .stream()
            .filter(tag -> tag.getObjectId().getName().equals(headBranch))
            .findFirst();
    if (currentTag.isPresent()) {
      currentRef = currentTag.get().getName();
    } else {
      currentRef = "refs/heads/" + headBranch;
    }

  } catch (GitAPIException | IOException exception) {
    throw new GitException(exception.getMessage(), exception);
  }
  List<Branch> branches = new ArrayList<>();
  for (Ref ref : refs) {
    String refName = ref.getName();
    boolean isCommitOrTag = HEAD.equals(refName);
    String branchName = isCommitOrTag ? currentRef : refName;
    String branchDisplayName;
    if (isCommitOrTag) {
      branchDisplayName = "(detached from " + Repository.shortenRefName(currentRef) + ")";
    } else {
      branchDisplayName = Repository.shortenRefName(refName);
    }
    Branch branch =
        newDto(Branch.class)
            .withName(branchName)
            .withActive(isCommitOrTag || refName.equals(currentRef))
            .withDisplayName(branchDisplayName)
            .withRemote(refName.startsWith("refs/remotes"));
    branches.add(branch);
  }
  return branches;
}
项目:verigreen    文件:JGitOperator.java   
@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();
           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;
   }
项目:spring-cloud-config    文件:JGitEnvironmentRepository.java   
private boolean isBranch(Git git, String label) throws GitAPIException {
    return containsBranch(git, label, ListMode.ALL);
}
项目:ivy-pdi-git-steps    文件:ListBranchsGitCommand.java   
public List<String[]> call(final GitInfoStep gitInfoStep, Git git,
    CredentialsProvider cp, String gitRepoUrl, File gitRepoFolder)
    throws InvalidRemoteException, TransportException, GitAPIException,
    IllegalArgumentException, IOException {

  final List<String[]> branchs = new ArrayList<String[]>();

  final ListBranchCommand ac = git
      .branchList()
      .setListMode(
          ("remote".equalsIgnoreCase(gitInfoStep
              .environmentSubstitute(this.listMode)) ? ListMode.REMOTE
              : ListMode.ALL));
  final List<Ref> refBranchs = ac.call();

  for (Ref refBranch : refBranchs) {
    final String[] branch = new String[] {null, null, null, null,
        null, null, null, null, null, null};

    branch[0] = refBranch.getObjectId().getName(); // Id
    branch[1] = refBranch.getName(); // Name

    final RevObject object = new RevWalk(git.getRepository())
        .parseAny(refBranch.getObjectId());
    if (object instanceof RevCommit) {
      branch[2] = ((RevCommit) object).getFullMessage(); // Commit
      // message
      branch[3] = ((RevCommit) object).getShortMessage(); // Commit
      // message
      branch[4] = dt.format(((RevCommit) object).getAuthorIdent()
          .getWhen()); // Author Date
      branch[5] = ((RevCommit) object).getAuthorIdent().getName(); // Author
      // name
      branch[6] = ((RevCommit) object).getAuthorIdent()
          .getEmailAddress(); // Author email
      branch[7] = dt.format(((RevCommit) object).getCommitterIdent()
          .getWhen()); // Committer Date
      branch[8] = ((RevCommit) object).getCommitterIdent().getName(); // Committer
      // name
      branch[9] = ((RevCommit) object).getCommitterIdent()
          .getEmailAddress(); // Committer email
    }

    branchs.add(branch);
  }

  return branchs;
}