Skip to content

Commit

Permalink
[git] IDEA-143026 Do not propose to delete a protected branch after m…
Browse files Browse the repository at this point in the history
…erge

Previously, the logic worked with the master branch only.

GitOrigin-RevId: 3d413996c91e5a984074c4288026701922394ac4
  • Loading branch information
dmitriysmirnovjb authored and intellij-monorepo-bot committed Jan 19, 2023
1 parent 6948cb4 commit 580050b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package git4idea.actions.branch

import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.Project
import git4idea.GitBranch
import git4idea.branch.GitBrancher
import git4idea.config.GitSharedSettings
import git4idea.i18n.GitBundle
import git4idea.log.GitRefManager
import git4idea.repo.GitRepository
import git4idea.ui.branch.GitBranchPopupActions.*

Expand All @@ -29,12 +29,11 @@ internal class GitMergeBranchAction : GitSingleBranchAction(GitBundle.messagePoi
}

override fun actionPerformed(e: AnActionEvent, project: Project, repositories: List<GitRepository>, branch: GitBranch) {
GitBrancher.getInstance(project).merge(branch.name, deleteOnMerge(branch), repositories)
GitBrancher.getInstance(project).merge(branch.name, deleteOnMerge(branch, project), repositories)
}

//TODO: remove hardcoded branch name
private fun deleteOnMerge(branch: GitBranch): GitBrancher.DeleteOnMergeOption {
return if (!branch.isRemote && branch.name != GitRefManager.MASTER) { // NON-NLS
private fun deleteOnMerge(branch: GitBranch, project: Project): GitBrancher.DeleteOnMergeOption {
return if (!branch.isRemote && !GitSharedSettings.getInstance(project).isBranchProtected(branch.name)) {
GitBrancher.DeleteOnMergeOption.PROPOSE
}
else GitBrancher.DeleteOnMergeOption.NOTHING
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package git4idea.ui.branch;

import com.intellij.dvcs.DvcsUtil;
Expand Down Expand Up @@ -28,6 +28,7 @@
import git4idea.actions.GitOngoingOperationAction;
import git4idea.actions.branch.GitBranchActionsUtil;
import git4idea.branch.*;
import git4idea.config.GitSharedSettings;
import git4idea.config.GitVcsSettings;
import git4idea.config.UpdateMethod;
import git4idea.fetch.GitFetchSupport;
Expand Down Expand Up @@ -1084,11 +1085,11 @@ public void update(@NotNull AnActionEvent e) {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
GitBrancher brancher = GitBrancher.getInstance(myProject);
brancher.merge(myBranchName, deleteOnMerge(), myRepositories);
brancher.merge(myBranchName, deleteOnMerge(myProject), myRepositories);
}

private GitBrancher.DeleteOnMergeOption deleteOnMerge() {
if (myLocalBranch && !myBranchName.equals("master")) { // NON-NLS
private GitBrancher.DeleteOnMergeOption deleteOnMerge(Project project) {
if (myLocalBranch && !GitSharedSettings.getInstance(project).isBranchProtected(myBranchName)) {
return GitBrancher.DeleteOnMergeOption.PROPOSE;
}
return GitBrancher.DeleteOnMergeOption.NOTHING;
Expand Down

0 comments on commit 580050b

Please sign in to comment.