mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 11:53:49 +07:00
[git/refactor] Cleanup duplicating branch and tag actions
GitOrigin-RevId: a9091e8e840483d17afb34e222db3b5a391d9d81
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bea9a43f2f
commit
5995f8f134
@@ -98,7 +98,7 @@ public final class DvcsUtil {
|
||||
}
|
||||
|
||||
public static <T extends Repository> void disableActionIfAnyRepositoryIsFresh(@NotNull AnActionEvent e,
|
||||
@NotNull List<T> repositories,
|
||||
@NotNull Collection<T> repositories,
|
||||
@Nls String operationName) {
|
||||
boolean isFresh = ContainerUtil.exists(repositories, Repository::isFresh);
|
||||
if (isFresh) {
|
||||
|
||||
@@ -19,7 +19,7 @@ import com.intellij.openapi.wm.impl.ToolbarComboButton
|
||||
import com.intellij.ui.components.BasicOptionButtonUI
|
||||
import com.intellij.ui.popup.PopupFactoryImpl
|
||||
import git4idea.GitLocalBranch
|
||||
import git4idea.actions.branch.GitCheckoutAction
|
||||
import git4idea.actions.ref.GitCheckoutAction
|
||||
import git4idea.actions.branch.GitCheckoutWithRebaseAction
|
||||
import git4idea.commands.Git
|
||||
import git4idea.commands.GitCommand
|
||||
|
||||
@@ -216,17 +216,15 @@
|
||||
</group>
|
||||
|
||||
<group id="Git.Branch">
|
||||
<action class="git4idea.actions.branch.GitCheckoutAction"/>
|
||||
<action class="git4idea.actions.tag.GitCheckoutTagAction"/>
|
||||
<action class="git4idea.actions.tag.GitDeleteTagAction"/>
|
||||
<action class="git4idea.actions.ref.GitCheckoutAction"/>
|
||||
<action class="git4idea.actions.branch.GitCheckoutAsNewBranch"/>
|
||||
<action class="git4idea.actions.branch.GitCheckoutWithRebaseAction"/>
|
||||
<separator/>
|
||||
<action class="git4idea.actions.branch.GitCompareWithBranchAction"/>
|
||||
<action class="git4idea.actions.branch.GitShowDiffWithBranchAction"/>
|
||||
<action class="git4idea.actions.ref.GitShowDiffWithRefAction"/>
|
||||
<separator/>
|
||||
<action class="git4idea.actions.branch.GitRebaseBranchAction"/>
|
||||
<action class="git4idea.actions.branch.GitMergeRefAction"/>
|
||||
<action class="git4idea.actions.ref.GitMergeRefAction"/>
|
||||
<separator/>
|
||||
<action class="git4idea.actions.branch.GitUpdateSelectedBranchAction"/>
|
||||
<action class="git4idea.actions.branch.GitPushBranchAction"/>
|
||||
@@ -234,7 +232,7 @@
|
||||
<action class="git4idea.actions.branch.GitPullBranchAction$WithMerge"/>
|
||||
<separator/>
|
||||
<action class="git4idea.actions.branch.GitRenameBranchAction" id="Git.Rename.Local.Branch"/>
|
||||
<action class="git4idea.actions.branch.GitDeleteBranchAction"/>
|
||||
<action class="git4idea.actions.ref.GitDeleteRefAction"/>
|
||||
</group>
|
||||
|
||||
<group id="Git.Menu" class="git4idea.actions.GitMenu" popup="true" searchable="false">
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
// Copyright 2000-2022 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.dvcs.diverged
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.project.Project
|
||||
import git4idea.GitBranch
|
||||
import git4idea.GitRemoteBranch
|
||||
import git4idea.branch.GitBrancher
|
||||
import git4idea.i18n.GitBundle
|
||||
import git4idea.remote.hosting.GitRemoteBranchesUtil
|
||||
import git4idea.repo.GitRepository
|
||||
|
||||
class GitCheckoutAction
|
||||
: GitSingleBranchAction(GitBundle.messagePointer("branches.checkout")) {
|
||||
|
||||
override fun isEnabledForRef(ref: GitBranch, repositories: List<GitRepository>)=
|
||||
if (isCurrentRefInAnyRepo(ref, repositories)) repositories.diverged() else true
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent, project: Project, repositories: List<GitRepository>, branch: GitBranch) {
|
||||
if (branch.isRemote) {
|
||||
GitRemoteBranchesUtil.checkoutRemoteBranch(project, repositories, branch.name)
|
||||
}
|
||||
else {
|
||||
GitBrancher.getInstance(e.project!!).checkout(branch.name, false, repositories, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
// 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.i18n.GitBundle
|
||||
import git4idea.isRemoteBranchProtected
|
||||
import git4idea.repo.GitRepository
|
||||
|
||||
class GitDeleteBranchAction
|
||||
: GitSingleBranchAction(GitBundle.messagePointer("branches.action.delete")) {
|
||||
|
||||
override fun isEnabledForRef(ref: GitBranch, repositories: List<GitRepository>) = !isCurrentRefInAnyRepo(ref, repositories)
|
||||
|
||||
override fun updateIfEnabledAndVisible(e: AnActionEvent, project: Project, repositories: List<GitRepository>, branch: GitBranch) {
|
||||
if (branch.isRemote) {
|
||||
e.presentation.isEnabled = !isRemoteBranchProtected(repositories, branch.name)
|
||||
}
|
||||
}
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent, project: Project, repositories: List<GitRepository>, branch: GitBranch) {
|
||||
val brancher = GitBrancher.getInstance(project)
|
||||
if (branch.isRemote) {
|
||||
brancher.deleteRemoteBranch(branch.name, repositories)
|
||||
}
|
||||
else {
|
||||
brancher.deleteBranch(branch.name, repositories.filter { branch != it.currentBranch })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ package git4idea.actions.branch
|
||||
import com.intellij.openapi.actionSystem.Presentation
|
||||
import com.intellij.openapi.util.NlsActions
|
||||
import git4idea.GitBranch
|
||||
import git4idea.actions.tag.GitSingleRefAction
|
||||
import git4idea.actions.ref.GitSingleRefAction
|
||||
import git4idea.repo.GitRepository
|
||||
import java.util.function.Supplier
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package git4idea.actions.ref
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.project.Project
|
||||
import git4idea.GitBranch
|
||||
import git4idea.GitReference
|
||||
import git4idea.GitRemoteBranch
|
||||
import git4idea.GitTag
|
||||
import git4idea.branch.GitBrancher
|
||||
import git4idea.i18n.GitBundle
|
||||
import git4idea.remote.hosting.GitRemoteBranchesUtil
|
||||
import git4idea.repo.GitRefUtil
|
||||
import git4idea.repo.GitRepository
|
||||
|
||||
class GitCheckoutAction
|
||||
: GitSingleRefAction<GitReference>(GitBundle.messagePointer("branches.checkout")) {
|
||||
|
||||
override fun isEnabledForRef(ref: GitReference, repositories: List<GitRepository>): Boolean {
|
||||
if (ref !is GitBranch && ref !is GitTag) return false
|
||||
|
||||
return if (isCurrentRefInAnyRepo(ref, repositories)) repositories.diverged() else true
|
||||
}
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent, project: Project, repositories: List<GitRepository>, reference: GitReference) {
|
||||
if (reference is GitRemoteBranch) {
|
||||
GitRemoteBranchesUtil.checkoutRemoteBranch(project, repositories, reference.name)
|
||||
}
|
||||
else {
|
||||
GitBrancher.getInstance(project).checkout(reference.fullName, false, repositories, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun List<GitRepository>.diverged(): Boolean {
|
||||
var sameRef: GitReference? = null
|
||||
|
||||
for (repo in this) {
|
||||
val ref = GitRefUtil.getCurrentReference(repo)
|
||||
if (sameRef == null) {
|
||||
sameRef = ref
|
||||
}
|
||||
else if (sameRef != ref) return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package git4idea.actions.ref
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.project.Project
|
||||
import git4idea.GitLocalBranch
|
||||
import git4idea.GitReference
|
||||
import git4idea.GitRemoteBranch
|
||||
import git4idea.GitTag
|
||||
import git4idea.branch.GitBrancher
|
||||
import git4idea.i18n.GitBundle
|
||||
import git4idea.isRemoteBranchProtected
|
||||
import git4idea.repo.GitRepository
|
||||
|
||||
class GitDeleteRefAction : GitSingleRefAction<GitReference>(GitBundle.messagePointer("branches.action.delete")) {
|
||||
override fun isEnabledForRef(ref: GitReference, repositories: List<GitRepository>) = !isCurrentRefInAnyRepo(ref, repositories)
|
||||
|
||||
override fun updateIfEnabledAndVisible(e: AnActionEvent, project: Project, repositories: List<GitRepository>, ref: GitReference) {
|
||||
if (ref is GitRemoteBranch) {
|
||||
e.presentation.isEnabled = !isRemoteBranchProtected(repositories, ref.name)
|
||||
}
|
||||
}
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent, project: Project, repositories: List<GitRepository>, reference: GitReference) {
|
||||
val brancher = GitBrancher.getInstance(project)
|
||||
when (reference) {
|
||||
is GitLocalBranch -> brancher.deleteBranch(reference.name, repositories.filter { it.currentBranch != reference })
|
||||
is GitRemoteBranch -> brancher.deleteRemoteBranch(reference.name, repositories)
|
||||
is GitTag -> brancher.deleteTag(reference.name, repositories)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package git4idea.actions.branch
|
||||
package git4idea.actions.ref
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.project.Project
|
||||
import git4idea.GitBranch
|
||||
import git4idea.GitReference
|
||||
import git4idea.actions.tag.GitSingleRefAction
|
||||
import git4idea.branch.GitBrancher
|
||||
import git4idea.config.GitSharedSettings
|
||||
import git4idea.i18n.GitBundle
|
||||
import git4idea.repo.GitRepository
|
||||
import git4idea.ui.branch.GitBranchPopupActions.*
|
||||
import git4idea.ui.branch.GitBranchPopupActions
|
||||
|
||||
internal class GitMergeRefAction : GitSingleRefAction<GitReference>(GitBundle.messagePointer("branches.merge.into.current")) {
|
||||
|
||||
@@ -23,14 +22,15 @@ internal class GitMergeRefAction : GitSingleRefAction<GitReference>(GitBundle.me
|
||||
override fun updateIfEnabledAndVisible(e: AnActionEvent, project: Project, repositories: List<GitRepository>, reference: GitReference) {
|
||||
with(e.presentation) {
|
||||
text = GitBundle.message("branches.merge.into",
|
||||
getSelectedBranchTruncatedPresentation(project, reference.name),
|
||||
getCurrentBranchTruncatedPresentation(project, repositories))
|
||||
GitBranchPopupActions.getSelectedBranchTruncatedPresentation(project, reference.name),
|
||||
GitBranchPopupActions.getCurrentBranchTruncatedPresentation(project, repositories))
|
||||
description = GitBundle.message("branches.merge.into",
|
||||
getSelectedBranchFullPresentation(reference.name),
|
||||
getCurrentBranchFullPresentation(project, repositories))
|
||||
addTooltipText(this, GitBundle.message("branches.merge.into",
|
||||
getSelectedBranchFullPresentation(reference.name),
|
||||
getCurrentBranchFullPresentation(project, repositories)))
|
||||
GitBranchPopupActions.getSelectedBranchFullPresentation(reference.name),
|
||||
GitBranchPopupActions.getCurrentBranchFullPresentation(project, repositories))
|
||||
GitBranchPopupActions.addTooltipText(this, GitBundle.message("branches.merge.into",
|
||||
GitBranchPopupActions.getSelectedBranchFullPresentation(reference.name),
|
||||
GitBranchPopupActions.getCurrentBranchFullPresentation(project,
|
||||
repositories)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,4 +40,4 @@ internal class GitMergeRefAction : GitSingleRefAction<GitReference>(GitBundle.me
|
||||
}
|
||||
else GitBrancher.DeleteOnMergeOption.NOTHING
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,23 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package git4idea.actions.branch
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package git4idea.actions.ref
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.project.Project
|
||||
import git4idea.GitBranch
|
||||
import git4idea.GitReference
|
||||
import git4idea.actions.tag.GitSingleRefAction
|
||||
import git4idea.branch.GitBrancher
|
||||
import git4idea.i18n.GitBundle
|
||||
import git4idea.repo.GitRepository
|
||||
import git4idea.ui.branch.GitBranchPopupActions.getSelectedBranchFullPresentation
|
||||
import git4idea.ui.branch.GitBranchPopupActions
|
||||
import git4idea.ui.branch.GitMultiRootBranchConfig
|
||||
|
||||
internal class GitShowDiffWithBranchAction
|
||||
internal class GitShowDiffWithRefAction
|
||||
: GitSingleRefAction<GitReference>(GitBundle.messagePointer("branches.show.diff.with.working.tree")) {
|
||||
|
||||
override fun updateIfEnabledAndVisible(e: AnActionEvent, project: Project, repositories: List<GitRepository>, reference: GitReference) {
|
||||
with(e.presentation) {
|
||||
isEnabledAndVisible = !GitMultiRootBranchConfig(repositories).diverged() || repositories.size == 1
|
||||
description = GitBundle.message("branches.compare.the.current.working.tree.with",
|
||||
getSelectedBranchFullPresentation(reference.name))
|
||||
GitBranchPopupActions.getSelectedBranchFullPresentation(reference.name))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package git4idea.actions.tag
|
||||
package git4idea.actions.ref
|
||||
|
||||
import com.intellij.dvcs.DvcsUtil
|
||||
import com.intellij.dvcs.repo.Repository
|
||||
@@ -1,19 +0,0 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package git4idea.actions.tag
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.project.Project
|
||||
import git4idea.GitTag
|
||||
import git4idea.branch.GitBrancher
|
||||
import git4idea.i18n.GitBundle
|
||||
import git4idea.repo.GitRepository
|
||||
|
||||
internal class GitCheckoutTagAction() : GitSingleTagAction(GitBundle.messagePointer("branches.checkout")) {
|
||||
|
||||
override fun isEnabledForRef(ref: GitTag, repositories: List<GitRepository>) = !isCurrentRefInAnyRepo(ref, repositories)
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent, project: Project, repositories: List<GitRepository>, reference: GitTag) {
|
||||
GitBrancher.getInstance(project).checkout(reference.fullName, false, repositories, null)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package git4idea.actions.tag
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.project.Project
|
||||
import git4idea.GitBranch
|
||||
import git4idea.GitTag
|
||||
import git4idea.branch.GitBrancher
|
||||
import git4idea.i18n.GitBundle
|
||||
import git4idea.repo.GitRepository
|
||||
|
||||
internal class GitDeleteTagAction : GitSingleTagAction(GitBundle.messagePointer("branches.action.delete")) {
|
||||
|
||||
override fun isEnabledForRef(ref: GitTag, repositories: List<GitRepository>) = !isCurrentRefInAnyRepo(ref, repositories)
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent, project: Project, repositories: List<GitRepository>, reference: GitTag) {
|
||||
GitBrancher.getInstance(project).deleteTag(reference.name, repositories)
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import com.intellij.openapi.actionSystem.DataSink
|
||||
import com.intellij.openapi.actionSystem.DataSnapshotProvider
|
||||
import git4idea.GitBranch
|
||||
import git4idea.actions.branch.GitBranchActionsDataKeys
|
||||
import git4idea.actions.tag.GitSingleRefAction
|
||||
import git4idea.actions.ref.GitSingleRefAction
|
||||
import git4idea.repo.GitRepository
|
||||
|
||||
internal class GitBranchActionWrapper(
|
||||
|
||||
Reference in New Issue
Block a user