Search in sources :

Example 1 with DeleteRemoteBranchDecision

use of git4idea.branch.GitBranchUiHandler.DeleteRemoteBranchDecision in project intellij-community by JetBrains.

the class GitDeleteRemoteBranchOperation method execute.

@Override
protected void execute() {
    Collection<GitRepository> repositories = getRepositories();
    Collection<String> commonTrackingBranches = getCommonTrackingBranches(myBranchName, repositories);
    // don't propose to remove current branch even if it tracks the remote branch
    for (GitRepository repository : repositories) {
        String currentBranch = repository.getCurrentBranchName();
        if (currentBranch != null) {
            commonTrackingBranches.remove(currentBranch);
        }
    }
    Ref<DeleteRemoteBranchDecision> decision = Ref.create();
    ApplicationManager.getApplication().invokeAndWait(() -> decision.set(myUiHandler.confirmRemoteBranchDeletion(myBranchName, commonTrackingBranches, repositories)));
    if (decision.get() != CANCEL) {
        boolean deletedSuccessfully = doDeleteRemote(myBranchName, repositories);
        if (deletedSuccessfully) {
            Collection<String> successfullyDeletedLocalBranches = new ArrayList<>(1);
            if (decision.get() == DELETE_WITH_TRACKING) {
                for (String branch : commonTrackingBranches) {
                    getIndicator().setText("Deleting " + branch);
                    new GitDeleteBranchOperation(myProject, myGit, myUiHandler, repositories, branch) {

                        @Override
                        protected void notifySuccess(@NotNull String message) {
                            // do nothing - will display a combo notification for all deleted branches below
                            successfullyDeletedLocalBranches.add(branch);
                        }
                    }.execute();
                }
            }
            notifySuccessfulDeletion(myBranchName, successfullyDeletedLocalBranches);
        }
    }
}
Also used : GitRepository(git4idea.repo.GitRepository) ArrayList(java.util.ArrayList) DeleteRemoteBranchDecision(git4idea.branch.GitBranchUiHandler.DeleteRemoteBranchDecision)

Aggregations

DeleteRemoteBranchDecision (git4idea.branch.GitBranchUiHandler.DeleteRemoteBranchDecision)1 GitRepository (git4idea.repo.GitRepository)1 ArrayList (java.util.ArrayList)1