org.eclipse.jgit.api.Git.branchList()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(162)

本文整理了Java中org.eclipse.jgit.api.Git.branchList()方法的一些代码示例,展示了Git.branchList()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Git.branchList()方法的具体详情如下:
包路径:org.eclipse.jgit.api.Git
类名称:Git
方法名:branchList

Git.branchList介绍

[英]Return a command object used to list branches
[中]返回用于列出分支的命令对象

代码示例

代码示例来源:origin: spring-cloud/spring-cloud-config

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;
}

代码示例来源:origin: gocd/gocd

public Long commitCountOnMaster() throws GitAPIException, IncorrectObjectTypeException, MissingObjectException {
    // not inside a doLocked/synchronized block because we don't want to block the server status service.
    // we do a `git branch` because we switch branches as part of normal git operations,
    // and we don't care about number of commits on those branches.
    List<Ref> branches = git.branchList().call();
    for (Ref branch : branches) {
      if (branch.getName().equals("refs/heads/master")) {
        Iterable<RevCommit> commits = git.log().add(branch.getObjectId()).call();
        long count = 0;
        for (RevCommit commit : commits) {
          count++;
        }
        return count;
      }
    }
    return Long.valueOf(-1);
  }
}

代码示例来源:origin: gocd/gocd

private List<Ref> getAllBranches() throws GitAPIException {
    return configRepo.git().branchList().setListMode(ListBranchCommand.ListMode.ALL).call();
  }
}

代码示例来源:origin: gocd/gocd

@Test
public void shouldSwitchToMasterAndDeleteTempBranches() throws Exception, GitAPIException {
  configRepo.checkin(goConfigRevision("v1", "md5-1"));
  configRepo.createBranch(ConfigRepository.BRANCH_AT_HEAD, configRepo.getCurrentRevCommit());
  configRepo.createBranch(ConfigRepository.BRANCH_AT_REVISION, configRepo.getCurrentRevCommit());
  configRepo.git().checkout().setName(ConfigRepository.BRANCH_AT_REVISION).call();
  assertThat(configRepo.git().getRepository().getBranch(), is(ConfigRepository.BRANCH_AT_REVISION));
  assertThat(configRepo.git().branchList().call().size(), is(3));
  configRepo.cleanAndResetToMaster();
  assertThat(configRepo.git().getRepository().getBranch(), is("master"));
  assertThat(configRepo.git().branchList().call().size(), is(1));
}

代码示例来源:origin: gocd/gocd

@Test
public void shouldCleanAndResetToMasterOnceMergeFlowIsComplete() throws Exception {
  String original = "first\nsecond\n";
  String changeOnBranch = "first\nsecond\nthird\n";
  String changeOnMaster = "1st\nsecond\n";
  String oldMd5 = "md5-1";
  configRepo.checkin(goConfigRevision(original, oldMd5));
  configRepo.checkin(goConfigRevision(changeOnMaster, "md5-2"));
  configRepo.getConfigMergedWithLatestRevision(goConfigRevision(changeOnBranch, "md5-3"), oldMd5);
  assertThat(configRepo.git().getRepository().getBranch(), is("master"));
  assertThat(configRepo.git().branchList().call().size(), is(1));
}

代码示例来源:origin: gocd/gocd

@Test
public void shouldCleanAndResetToMasterDuringInitialization() throws Exception {
  configRepo.checkin(goConfigRevision("v1", "md5-1"));
  configRepo.createBranch(ConfigRepository.BRANCH_AT_REVISION, configRepo.getCurrentRevCommit());
  configRepo.git().checkout().setName(ConfigRepository.BRANCH_AT_REVISION).call();
  assertThat(configRepo.git().getRepository().getBranch(), is(ConfigRepository.BRANCH_AT_REVISION));
  new ConfigRepository(systemEnvironment).initialize();
  assertThat(configRepo.git().getRepository().getBranch(), is("master"));
  assertThat(configRepo.git().branchList().call().size(), is(1));
}

代码示例来源:origin: jphp-group/jphp

@Signature
public Memory branchList(ArrayMemory settings) throws GitAPIException {
  ListBranchCommand command = getWrappedObject().branchList();
  if (settings != null) {
    Memory listMode = settings.valueOfIndex("listMode");
    if (listMode.isNotNull()) {
      command.setListMode(ListBranchCommand.ListMode.valueOf(listMode.toString()));
    }
    Memory contains = settings.valueOfIndex("contains");
    if (contains.isNotNull()) {
      command.setContains(contains.toString());
    }
  }
  return GitUtils.valueOfRefs(command.call());
}

代码示例来源:origin: FlowCI/flow-platform

private boolean checkExistBranchOrNot(Path path) {
    try (Git git = Git.open(path.toFile())) {
      if (git.branchList().call().isEmpty()) {
        return false;
      }
    } catch (Throwable e) {
      log.error("Method: checkExistBranchOrNot Exception", e);
    }
    return true;
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
  try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
    try (Git git = new Git(repository)) {
      List<Ref> call = git.branchList().call();
      for (Ref ref : call) {
        List<Integer> counts = getCounts(repository, ref.getName());
        System.out.println("For branch: " + ref.getName());
        System.out.println("Commits ahead : " + counts.get(0));
        System.out.println("Commits behind : " + counts.get(1));
        System.out.println();
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
  try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
    try (Git git = new Git(repository)) {
      List<Ref> call = git.branchList().call();
      for (Ref ref : call) {
        List<Integer> counts = getCounts(repository, ref.getName());
        System.out.println("For branch: " + ref.getName());
        System.out.println("Commits ahead : " + counts.get(0));
        System.out.println("Commits behind : " + counts.get(1));
        System.out.println();
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      System.out.println("Listing local branches:");
      try (Git git = new Git(repository)) {
        List<Ref> call = git.branchList().call();
        for (Ref ref : call) {
          System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
        }

        System.out.println("Now including remote branches:");
        call = git.branchList().setListMode(ListMode.ALL).call();
        for (Ref ref : call) {
          System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
        }
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      System.out.println("Listing local branches:");
      try (Git git = new Git(repository)) {
        List<Ref> call = git.branchList().call();
        for (Ref ref : call) {
          System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
        }

        System.out.println("Now including remote branches:");
        call = git.branchList().setListMode(ListMode.ALL).call();
        for (Ref ref : call) {
          System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
        }
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

List<Ref> call = git.branchList().call();
for (Ref ref : call) {
  System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
call = git.branchList().setListMode(ListMode.ALL).call();
for (Ref ref : call) {
  System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());

代码示例来源:origin: centic9/jgit-cookbook

List<Ref> call = git.branchList().call();
for (Ref ref : call) {
  System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
call = git.branchList().setListMode(ListMode.ALL).call();
for (Ref ref : call) {
  System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());

代码示例来源:origin: centic9/jgit-cookbook

List<Ref> call = git.branchList().call();
for (Ref ref : call) {
  System.out.println("Branch-Before: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
List<Ref> refs = git.branchList().call();
for(Ref ref : refs) {
  System.out.println("Had branch: " + ref.getName());
    .call();
call = git.branchList().call();
for (Ref ref : call) {
  System.out.println("Branch-Created: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
    .call();
call = git.branchList().call();
for (Ref ref : call) {
  System.out.println("Branch-After: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());

代码示例来源:origin: centic9/jgit-cookbook

List<Ref> call = git.branchList().call();
for (Ref ref : call) {
  System.out.println("Branch-Before: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
List<Ref> refs = git.branchList().call();
for(Ref ref : refs) {
  System.out.println("Had branch: " + ref.getName());
    .call();
call = git.branchList().call();
for (Ref ref : call) {
  System.out.println("Branch-Created: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
    .call();
call = git.branchList().call();
for (Ref ref : call) {
  System.out.println("Branch-After: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
  try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
    try (Git git = new Git(repository)) {
      List<Ref> refs = git.branchList().call();
      for (Ref ref : refs) {
        System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
        listReflog(repository, ref);
      }
      List<Ref> call = git.tagList().call();
      for (Ref ref : call) {
        System.out.println("Tag: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
        listReflog(repository, ref);
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
  try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
    try (Git git = new Git(repository)) {
      List<Ref> refs = git.branchList().call();
      for (Ref ref : refs) {
        System.out.println("Branch: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
        listReflog(repository, ref);
      }
      List<Ref> call = git.tagList().call();
      for (Ref ref : call) {
        System.out.println("Tag: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
        listReflog(repository, ref);
      }
    }
  }
}

代码示例来源:origin: org.jboss.forge.addon/git-impl

@Override
public List<Ref> getLocalBranches(final Git repo) throws GitAPIException
{
 // returns only local branches by default
 return repo.branchList().call();
}

代码示例来源:origin: ch.sbb.releasetrain/status

private boolean remoteBranchExists(final Git git) throws GitAPIException {
  List<Ref> branchRefs = git.branchList().setListMode(ListBranchCommand.ListMode.ALL).call();
  final String refsHeadBranch = "refs/remotes/origin/" + branch;
  for (Ref branchRef : branchRefs) {
    if (refsHeadBranch.equals(branchRef.getName())) {
      return true;
    }
  }
  return false;
}

相关文章