mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
git: don't allow to delete a protected remote branch: IDEA-194090
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user