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; }
private List<Ref> getAllBranches() throws GitAPIException { return configRepo.git().branchList().setListMode(ListBranchCommand.ListMode.ALL).call(); } }
@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()); }
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()); } } } } }
call = git.branchList().setListMode(ListMode.ALL).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());
protected List<String> doListBranches(Git git) throws GitAPIException { SortedSet<String> names = new TreeSet<String>(); List<Ref> call = git.branchList().setListMode(ListBranchCommand.ListMode.ALL).call(); for (Ref ref : call) { String name = ref.getName(); int idx = name.lastIndexOf('/'); if (idx >= 0) { name = name.substring(idx + 1); } if (name.length() > 0) { names.add(name); } } return new ArrayList<String>(names); }
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; }
public static List<Ref> branchList(final Git git, final ListBranchCommand.ListMode listMode) { checkNotNull("git", git); try { return git.branchList().setListMode(listMode).call(); } catch (GitAPIException e) { throw new RuntimeException(e); } }
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; }
public static List<Ref> branchList( final Git git, final ListBranchCommand.ListMode listMode ) { checkNotNull( "git", git ); try { return git.branchList().setListMode( listMode ).call(); } catch ( GitAPIException e ) { throw new RuntimeException( e ); } }
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; } updateExchange(exchange, result); }
public boolean isBranch(String branchname) throws Exception { log.trace("Checking if {} is a branch on {}", branchname, getRemoteRepository()); for(Ref ref : git.branchList().setListMode(ListMode.ALL).call()){ log.trace("Checking {}, {}", ref.getName(), branchname); if(ref.getName().equals("refs/heads/"+branchname) || ref.getName().equals("refs/remotes/origin/"+branchname)) { return true; } } return false; }
public Set<Branch> getBranchesInternal(ListBranchCommand.ListMode mode) throws GitException { try (Repository repo = getRepository()) { List<Ref> refs = git(repo).branchList().setListMode(mode).call(); Set<Branch> branches = new HashSet<>(refs.size()); for (Ref ref : refs) { branches.add(new Branch(ref)); } return branches; } catch (GitAPIException e) { throw new GitException(e); } }
private void checkoutAllBranches(Repository repository) throws GitAPIException { final Git git = Git.wrap(repository); for (final Ref ref : git.branchList().setListMode(ListBranchCommand.ListMode.REMOTE).call()) { final String refName = ref.getName(); final String branchName = refName.substring(refName.lastIndexOf('/') + 1); try { git.checkout().setCreateBranch(true).setName(branchName).setStartPoint("origin/" + branchName).call(); } catch (RefAlreadyExistsException e) { LOGGER.warning("Already exists, so ignoring " + e.getMessage()); } } }
public List<Branch> getRemoteBranches() throws GitException, IOException { verifyGitRepository(); List<Ref> refList; try { refList = jGitDelegate.branchList().setListMode(ListBranchCommand.ListMode.REMOTE).call(); } catch (GitAPIException ex) { throw new GitException(ex); } return parseRefList(refList); }
public List<Branch> getBranches() throws GitException { verifyGitRepository(); List<Ref> refList; try { refList = jGitDelegate.branchList().setListMode(ListBranchCommand.ListMode.ALL).call(); } catch (GitAPIException ex) { throw new GitException(ex); } return parseRefList(refList); }
@Test public void shouldGetBranchesWithLocalMode() throws Exception { // print = true; ListMode mode = null; ListBranchCommand command = git.branchList(); command.setListMode(mode); for (Ref ref : command.call()) { String fullName = ref.getName(); String name = fullName.replaceFirst("refs/heads/", ""); print(fullName + " \t--> " + name); } }
@Test public void shouldGetBranchesWithAllMode() throws Exception { // print = true; ListMode mode = ListMode.ALL; ListBranchCommand command = git.branchList(); command.setListMode(mode); for (Ref ref : command.call()) { print(ref.getName()); } }