void () { Collection<GitRepository> repositories = getRepositories(); Collection<String> allTrackingBranches = new ArrayList<>(); MultiMap<String, String> branchToCommonTrackingBranches = new MultiMap<>(); Ref<DeleteRemoteBranchDecision> decisionRef = Ref.create(); for (String branchName : myBranchNames) { Collection<String> commonTrackingBranches = getCommonTrackingBranches(branchName, 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); } } allTrackingBranches.addAll(commonTrackingBranches); branchToCommonTrackingBranches.put(branchName, commonTrackingBranches); } ApplicationManager.getApplication().invokeAndWait(() -> decisionRef.set( myUiHandler.confirmRemoteBranchDeletion(myBranchNames, allTrackingBranches, repositories))); DeleteRemoteBranchDecision decision = decisionRef.get(); if (decision == CANCEL) return; for (String branchName : myBranchNames) { boolean deletedSuccessfully = doDeleteRemote(branchName, repositories); if (deletedSuccessfully) { Collection<String> successfullyDeletedLocalBranches = new ArrayList<>(1); if (decision == DELETE_WITH_TRACKING) { for (String branch : branchToCommonTrackingBranches.get(branchName)) { getIndicator().setText(GitBundle.message("delete.remote.branch.operation.deleting.process", branch)); new GitDeleteBranchOperation(myProject, myGit, myUiHandler, repositories, branch) { @Override protected void notifySuccess() { // do nothing - will display a combo notification for all deleted branches below successfullyDeletedLocalBranches.add(branch); } }.execute(); } } notifySuccessfulDeletion(branchName, successfullyDeletedLocalBranches); } } }