/** @return name of branch, e.g. 'origin/master' -> 'master' */ private String getSelectedBranchName() { String selectedBranchName = selectedBranch.getDisplayName(); String[] tokens = selectedBranchName.split("/"); return tokens.length > 0 ? tokens[tokens.length - 1] : selectedBranchName; }
/** * Get simple names of local branches. * * @param localBranches local branches */ @NotNull public List<String> getLocalBranchesToDisplay(@NotNull List<Branch> localBranches) { List<String> branches = new ArrayList<>(); if (localBranches.isEmpty()) { branches.add("master"); return branches; } for (Branch branch : localBranches) { branches.add(branch.getDisplayName()); } return branches; } }
@Override public void setRemoteBranchesList(List<Branch> branches) { remoteBranches.clear(); branches.forEach(branch -> remoteBranches.addItem(branch.getDisplayName())); }
public BranchImpl(org.eclipse.che.api.git.shared.Branch origin) { this.name = origin.getName(); this.displayName = origin.getDisplayName(); this.remote = origin.isRemote(); this.active = origin.isActive(); }
writer.write(branch.getName().substring(5)); // trim leading 'refs/' } else { writer.write(branch.getDisplayName());
@Override public void onSuccess(List<Branch> result) { List<String> localBranches = branchSearcher.getLocalBranchesToDisplay(result); view.setLocalBranches(localBranches); for (Branch branch : result) { if (branch.isActive()) { view.selectLocalBranch(branch.getDisplayName()); break; } } // getting remote branch only after selecting current local branch updateRemoteBranches(); }
@Override public void onCheckoutClicked() { final CheckoutRequest checkoutRequest = dtoFactory.createDto(CheckoutRequest.class); if (selectedBranch.isRemote()) { checkoutRequest.setTrackBranch(selectedBranch.getDisplayName()); } else { checkoutRequest.setName(selectedBranch.getDisplayName()); } service .checkout(project.getLocation(), checkoutRequest) .then( ignored -> { view.closeDialogIfShowing(); }) .catchError( error -> { handleError(error.getCause(), BRANCH_CHECKOUT_COMMAND_NAME); }); }
private void renameBranch(String newName) { service .branchRename(project.getLocation(), selectedBranch.getDisplayName(), newName) .then( ignored -> { getBranches(); view.setFocus(); }) .catchError( error -> { handleError(error.getCause(), BRANCH_RENAME_COMMAND_NAME); getBranches(); // rename of remote branch occurs in three stages, so needs update list // of branches on view }); }
private void checkoutBranch( GitConnection git, String projectName, String branchName, String startPoint) throws GitException { final CheckoutParams params = CheckoutParams.create(branchName); final boolean branchExist = git.branchList(LIST_ALL) .stream() .anyMatch(branch -> branch.getDisplayName().equals("origin/" + branchName)); final GitCheckoutEvent checkout = newDto(GitCheckoutEvent.class) .withWorkspaceId(WorkspaceIdProvider.getWorkspaceId()) .withProjectName(projectName); if (startPoint != null) { if (branchExist) { git.checkout(params); eventService.publish( checkout.withCheckoutOnly(true).withBranchRef(getRemoteBranch(git, branchName))); } else { checkoutAndRethrow( git, params.withCreateNew(true).withStartPoint(startPoint).withNoTrack(true), FAILED_CHECKOUT_WITH_START_POINT); eventService.publish(checkout.withCheckoutOnly(false)); } } else { checkoutAndRethrow(git, params, FAILED_CHECKOUT); eventService.publish( checkout.withCheckoutOnly(true).withBranchRef(getRemoteBranch(git, branchName))); } }
if (!branch.isActive()) { Reference reference = new Reference(branch.getName(), branch.getDisplayName(), LOCAL_BRANCH); references.add(reference); if (!branch.isActive()) { Reference reference = new Reference(branch.getName(), branch.getDisplayName(), REMOTE_BRANCH); references.add(reference);
/** * Update the list of branches. * * @param remoteMode is a remote mode */ private void updateBranches(@NotNull final BranchListMode remoteMode) { service .branchList(project.getLocation(), remoteMode) .then( branches -> { if (LIST_REMOTE.equals(remoteMode)) { view.setRemoteBranches( branchSearcher.getRemoteBranchesToDisplay(view.getRepositoryName(), branches)); updateBranches(LIST_LOCAL); } else { view.setLocalBranches(branchSearcher.getLocalBranchesToDisplay(branches)); for (Branch branch : branches) { if (branch.isActive()) { view.selectRemoteBranch(branch.getDisplayName()); break; } } } }) .catchError( error -> { handleError(error.getCause(), BRANCH_LIST_COMMAND_NAME); view.setEnablePullButton(false); }); }
for (Branch branch : branches) { if (branch.isActive()) { view.selectRemoteBranch(branch.getDisplayName()); break;