/** * Gets current branch name. * * @return name of current branch or <code>null</code> if current branch not exists * @throws GitException if any error occurs */ private String getCurrentBranch() throws GitException { BranchListCommand command = nativeGit.createBranchListCommand(); command.execute(); String branchName = null; for (String outLine : command.getLines()) { if (outLine.indexOf('*') != -1) { branchName = outLine.substring(2); } } return branchName; }
@Override public List<Branch> branchList(BranchListRequest request) throws GitException { String listMode = request.getListMode(); if (listMode != null && !(listMode.equals(BranchListRequest.LIST_ALL) || listMode.equals(BranchListRequest.LIST_REMOTE))) { throw new IllegalArgumentException( "Unsupported list mode '" + listMode + "'. Must be either 'a' or 'r'. "); } List<Branch> branches; BranchListCommand branchListCommand = nativeGit.createBranchListCommand(); if (request.getListMode() == null) { branches = branchListCommand.execute(); } else if (request.getListMode().equals(BranchListRequest.LIST_ALL)) { branches = branchListCommand.execute(); branches.addAll(branchListCommand.setShowRemotes(true).execute()); } else { branches = branchListCommand.setShowRemotes(true).execute(); } return branches; }