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; }
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); } }
private List<Ref> getAllBranches() throws GitAPIException { return configRepo.git().branchList().setListMode(ListBranchCommand.ListMode.ALL).call(); } }
@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)); }
@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)); }
@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)); }
@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()); }
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; } }
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(); } } } }
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(); } } } }
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()); } } } } }
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()); } } } } }
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());
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());
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());
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());
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); } } } }
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); } } } }
@Override public List<Ref> getLocalBranches(final Git repo) throws GitAPIException { // returns only local branches by default return repo.branchList().call(); }
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; }