git: don't allow to delete a protected remote branch: IDEA-194090

This commit is contained in:
Kirill Likhodedov
2018-06-17 17:11:47 +03:00
parent fa656758a5
commit b57389ef96
2 changed files with 15 additions and 0 deletions
@@ -22,6 +22,15 @@ fun findProtectedRemoteBranch(repository: GitRepository, branches: Collection<St
firstOrNull { branches.contains(it) }
}
/**
* Checks if the given remote branch is protected.
*
* @param branchName the name of the remote branch in the "local" format, e.g. `origin/master`
*/
fun isRemoteBranchProtected(repositories: Collection<GitRepository>, branchName: String): Boolean {
return repositories.any { findProtectedRemoteBranch(it, listOf(branchName)) != null }
}
fun findProtectedRemoteBranchContainingCommit(repository: GitRepository, hash: Hash): String? {
val root = repository.root
val branchesGetter = VcsProjectLog.getInstance(repository.project).dataManager?.containingBranchesGetter
@@ -29,6 +29,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.ui.EmptyIcon;
import git4idea.GitBranch;
import git4idea.GitLocalBranch;
import git4idea.GitProtectedBranchesKt;
import git4idea.actions.GitAbstractRebaseAction;
import git4idea.branch.*;
import git4idea.config.GitVcsSettings;
@@ -518,6 +519,11 @@ class GitBranchPopupActions {
brancher.deleteRemoteBranch(myBranchName, myRepositories);
reportUsage(myProject, "git.branch.delete.remote");
}
@Override
public void update(AnActionEvent e) {
e.getPresentation().setEnabled(!GitProtectedBranchesKt.isRemoteBranchProtected(myRepositories, myBranchName));
}
}
}