/** * Checks that branch linked to remote. * * @param branch branch for checking * @return {@code true} if branch linked to remote and else returns {@code false} */ public boolean isLinkedTo(Branch branch) { return branch.getName().startsWith(refsForRemoteRepository); }
/** * Determines simple name of branch. Example difference between name and simple name: name of * branch equals "refs/remotes/origin/master" and simple name of branch equals "master" * * @return simple name of branch */ public String getBranchNameWithoutRefs(Branch branch) { return branch .getName() .replaceFirst(refsForRemoteRepository, "") .replaceFirst("refs/heads/", ""); } }
/** * Returns simple name of the given branch. E.g.: for a branch with name * "refs/remotes/origin/master" returns "master". Returns full name of the given branch if there's * no correspondent remote branch. */ private String getRemoteBranchNameWithoutRefs(GitConnection git, Branch branch) throws GitException { String branchName = branch.getName().replaceFirst("refs/remotes/", ""); List<Remote> remotes = git.remoteList(null, false); for (Remote remote : remotes) { if (branchName.startsWith(remote.getName())) { return branchName.replaceFirst(remote.getName() + "/", ""); } } return branchName; } }
private String getRemoteBranch(GitConnection git, String branchName) throws GitException { final List<Branch> remotes = git.branchList(LIST_REMOTE); for (Branch branch : remotes) { if (branchName.equals(getRemoteBranchNameWithoutRefs(git, branch))) { return branch.getName(); } } throw new GitException("Failed to get remote branch name", FAILED_CHECKOUT); }
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(); }
@Override public void onDeleteClicked() { dialogFactory .createConfirmDialog( constant.branchDelete(), constant.branchDeleteAsk(getSelectedBranchName()), () -> service .branchDelete(project.getLocation(), selectedBranch.getName(), true) .then( ignored -> { getBranches(); view.setFocus(); }) .catchError( error -> { handleError(error.getCause(), BRANCH_DELETE_COMMAND_NAME); }), null) .show(); }