[git] Remove CheckoutSelectedBranchAction

It's duplicated by `GitCheckoutAction`.

However, keep `CheckoutAction#checkoutBranch` and `CheckoutRemoteBranchAction#checkoutRemoteBranch` marking them for removal

GitOrigin-RevId: 299ae1346bd3e973300819c41f2dcb95385c4eee
This commit is contained in:
Ilia.Shulgin
2024-09-16 14:11:37 +02:00
committed by intellij-monorepo-bot
parent df277b3706
commit 16eca28411
6 changed files with 76 additions and 115 deletions

View File

@@ -32,7 +32,6 @@
<action id="Git.Reword.Commit" class="git4idea.rebase.GitRewordAction"/>
<action id="Git.Squash.Commits" class="git4idea.rebase.log.squash.GitSquashLogAction"/>
<action id="Git.Drop.Commits" class="git4idea.rebase.log.drop.GitDropLogAction"/>
<action id="Git.Checkout.Branch" class="git4idea.ui.branch.dashboard.BranchesDashboardActions$CheckoutSelectedBranchAction"/>
<action id="Git.New.Branch.In.Log" class="git4idea.ui.branch.dashboard.BranchesDashboardActions$NewBranchAction"/>
<action id="Git.Log.Branches.Change.Branch.Filter"
class="git4idea.ui.branch.dashboard.BranchesDashboardActions$UpdateBranchFilterInLogAction">

View File

@@ -647,8 +647,6 @@ group.Git.Local.Branch.title=Local
group.Git.Remote.Branch.title=Remote
group.Git.Tags.title=Tags
group.Git.Tags.loading.text=Loading\u2026
action.Git.Checkout.Branch.text=Checkout Selected\u2026
action.Git.Checkout.Branch.description=Checkout selected branch
action.Git.Log.Hide.Branches.text=Hide Git Branches
action.Git.Log.Show.Branches.text=Branches
action.Git.Reword.Commit.text=Edit Commit Message\u2026

View File

@@ -5,10 +5,11 @@ 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
import git4idea.ui.branch.GitBranchPopupActions
class GitCheckoutAction
: GitSingleBranchAction(GitBundle.messagePointer("branches.checkout")) {
@@ -18,8 +19,9 @@ class GitCheckoutAction
override fun actionPerformed(e: AnActionEvent, project: Project, repositories: List<GitRepository>, branch: GitBranch) {
if (branch.isRemote) {
GitBranchPopupActions.RemoteBranchActions.CheckoutRemoteBranchAction.checkoutRemoteBranch(project, repositories, branch.name)
} else {
GitRemoteBranchesUtil.checkoutRemoteBranch(project, repositories, branch.name)
}
else {
GitBrancher.getInstance(e.project!!).checkout(branch.name, false, repositories, null)
}
}

View File

@@ -13,11 +13,10 @@ import com.intellij.util.concurrency.annotations.RequiresBackgroundThread
import com.intellij.util.concurrency.annotations.RequiresEdt
import com.intellij.vcs.log.impl.VcsProjectLog
import com.intellij.vcs.log.visible.filters.VcsLogFilterObject
import git4idea.GitLocalBranch
import git4idea.GitRemoteBranch
import git4idea.GitStandardRemoteBranch
import git4idea.GitUtil
import git4idea.*
import git4idea.branch.GitBrancher
import git4idea.branch.GitNewBranchDialog
import git4idea.branch.GitNewBranchOptions
import git4idea.commands.Git
import git4idea.fetch.GitFetchSupport
import git4idea.i18n.GitBundle
@@ -25,7 +24,8 @@ import git4idea.push.GitSpecialRefRemoteBranch
import git4idea.repo.GitRemote
import git4idea.repo.GitRepoInfo
import git4idea.repo.GitRepository
import git4idea.ui.branch.GitBranchPopupActions
import git4idea.ui.branch.GitBranchCheckoutOperation
import git4idea.ui.branch.hasTrackingConflicts
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.net.URI
@@ -197,12 +197,56 @@ object GitRemoteBranchesUtil {
?: newLocalBranchPrefix?.let { "$it/${branch.nameForRemoteOperations}" }
?: branch.nameForRemoteOperations
GitBranchPopupActions.RemoteBranchActions.CheckoutRemoteBranchAction
.checkoutRemoteBranch(repository.project, listOf(repository), branch.name, suggestedName, callInAwtLater)
checkoutRemoteBranch(repository.project, listOf(repository), branch.name, suggestedName, callInAwtLater)
}
}
}
@RequiresEdt
@JvmStatic
fun checkoutRemoteBranch(project: Project, repositories: List<GitRepository>, remoteBranchName: String) {
val suggestedLocalName = repositories.firstNotNullOf { it.branches.findRemoteBranch(remoteBranchName)?.nameForRemoteOperations }
checkoutRemoteBranch(project, repositories, remoteBranchName, suggestedLocalName, null)
}
@RequiresEdt
private fun checkoutRemoteBranch(project: Project, repositories: List<GitRepository>, remoteBranchName: String, suggestedLocalName: String, callInAwtLater: Runnable?) {
// can have remote conflict if git-svn is used - suggested local name will be equal to selected remote
if (GitReference.BRANCH_NAME_HASHING_STRATEGY.equals(remoteBranchName, suggestedLocalName)) {
askNewBranchNameAndCheckout(project, repositories, remoteBranchName, suggestedLocalName, callInAwtLater)
return
}
val conflictingLocalBranches = repositories.mapNotNull { repo ->
repo.branches.findLocalBranch(suggestedLocalName)?.let { repo to it }
}.toMap()
if (hasTrackingConflicts(conflictingLocalBranches, remoteBranchName)) {
askNewBranchNameAndCheckout(project, repositories, remoteBranchName, suggestedLocalName, callInAwtLater)
} else {
GitBranchCheckoutOperation(project, repositories)
.perform(remoteBranchName, GitNewBranchOptions(suggestedLocalName, true, true), callInAwtLater)
}
}
@RequiresEdt
private fun askNewBranchNameAndCheckout(
project: Project, repositories: List<GitRepository>, remoteBranchName: String, suggestedLocalName: String, callInAwtLater: Runnable?,
) {
// Do not allow name conflicts
val options = GitNewBranchDialog(
project,
repositories,
GitBundle.message("branches.checkout.s", remoteBranchName),
suggestedLocalName,
false,
true
).showAndGetOptions() ?: return
GitBrancher.getInstance(project).checkoutNewBranchStartingFrom(options.name,
remoteBranchName,
options.reset,
repositories,
callInAwtLater)
}
private suspend fun showRemoteBranchInLog(repository: GitRepository,
branch: GitRemoteBranch,

View File

@@ -25,6 +25,7 @@ import git4idea.branch.GitNewBranchDialog;
import git4idea.branch.GitNewBranchOptions;
import git4idea.config.GitSharedSettings;
import git4idea.i18n.GitBundle;
import git4idea.remote.hosting.GitRemoteBranchesUtil;
import git4idea.repo.GitRepository;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
@@ -272,23 +273,15 @@ public final class GitBranchPopupActions {
return GitBundle.message("branches.there.are.outgoing.commits");
}
public static class CheckoutAction extends DumbAwareAction {
private final Project myProject;
private final List<? extends GitRepository> myRepositories;
private final String myBranchName;
public CheckoutAction(@NotNull Project project, @NotNull List<? extends GitRepository> repositories, @NotNull String branchName) {
super(GitBundle.messagePointer("branches.checkout"));
myProject = project;
myRepositories = repositories;
myBranchName = branchName;
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
checkoutBranch(myProject, myRepositories, myBranchName);
}
/**
* @deprecated use {@link GitBrancher}
*/
@Deprecated(forRemoval = true)
public final static class CheckoutAction {
/**
* @deprecated use {@link GitBrancher#checkout(String, boolean, List, Runnable))}
*/
@Deprecated(forRemoval = true)
public static void checkoutBranch(@NotNull Project project,
@NotNull List<? extends GitRepository> repositories,
@NotNull String branchName) {
@@ -332,67 +325,19 @@ public final class GitBranchPopupActions {
return getSingleBranchActions(myBranch, myRepositories, mySelectedRepository, e);
}
public static class CheckoutRemoteBranchAction extends DumbAwareAction {
private final Project myProject;
private final List<? extends GitRepository> myRepositories;
private final String myRemoteBranchName;
CheckoutRemoteBranchAction(@NotNull Project project, @NotNull List<? extends GitRepository> repositories,
@NotNull String remoteBranchName) {
super(GitBundle.messagePointer("branches.checkout"));
myProject = project;
myRepositories = repositories;
myRemoteBranchName = remoteBranchName;
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
checkoutRemoteBranch(myProject, myRepositories, myRemoteBranchName);
}
/**
* @deprecated use {@link GitRemoteBranchesUtil}
*/
@Deprecated(forRemoval = true)
public static final class CheckoutRemoteBranchAction {
/**
* @deprecated use {@link GitRemoteBranchesUtil#checkoutRemoteBranch(Project, List, String, String, Runnable)}
*/
@Deprecated(forRemoval = true)
@RequiresEdt
public static void checkoutRemoteBranch(@NotNull Project project, @NotNull List<? extends GitRepository> repositories,
@NotNull String remoteBranchName) {
GitRepository repository = repositories.get(0);
GitRemoteBranch remoteBranch = Objects.requireNonNull(repository.getBranches().findRemoteBranch(remoteBranchName));
String suggestedLocalName = remoteBranch.getNameForRemoteOperations();
checkoutRemoteBranch(project, repositories, remoteBranchName, suggestedLocalName, null);
}
@RequiresEdt
public static void checkoutRemoteBranch(@NotNull Project project, @NotNull List<? extends GitRepository> repositories,
@NotNull String remoteBranchName, @NotNull String suggestedLocalName, @Nullable Runnable callInAwtLater) {
// can have remote conflict if git-svn is used - suggested local name will be equal to selected remote
if (BRANCH_NAME_HASHING_STRATEGY.equals(remoteBranchName, suggestedLocalName)) {
askNewBranchNameAndCheckout(project, repositories, remoteBranchName, suggestedLocalName, callInAwtLater);
return;
}
Map<GitRepository, GitLocalBranch> conflictingLocalBranches = map2MapNotNull(repositories, r -> {
GitLocalBranch local = r.getBranches().findLocalBranch(suggestedLocalName);
return local != null ? Pair.create(r, local) : null;
});
if (hasTrackingConflicts(conflictingLocalBranches, remoteBranchName)) {
askNewBranchNameAndCheckout(project, repositories, remoteBranchName, suggestedLocalName, callInAwtLater);
return;
}
new GitBranchCheckoutOperation(project, repositories)
.perform(remoteBranchName, new GitNewBranchOptions(suggestedLocalName, true, true), callInAwtLater);
}
@RequiresEdt
private static void askNewBranchNameAndCheckout(@NotNull Project project, @NotNull List<? extends GitRepository> repositories,
@NotNull String remoteBranchName, @NotNull String suggestedLocalName,
@Nullable Runnable callInAwtLater) {
//do not allow name conflicts
GitNewBranchOptions options =
new GitNewBranchDialog(project, repositories, GitBundle.message("branches.checkout.s", remoteBranchName), suggestedLocalName,
false, true)
.showAndGetOptions();
if (options == null) return;
GitBrancher brancher = GitBrancher.getInstance(project);
brancher.checkoutNewBranchStartingFrom(options.getName(), remoteBranchName, options.shouldReset(), repositories, callInAwtLater);
GitRemoteBranchesUtil.checkoutRemoteBranch(project, repositories, remoteBranchName);
}
}
}

View File

@@ -5,7 +5,6 @@ import com.intellij.dvcs.DvcsUtil.disableActionIfAnyRepositoryIsFresh
import com.intellij.dvcs.branch.GroupingKey
import com.intellij.dvcs.diverged
import com.intellij.dvcs.getCommonCurrentBranch
import com.intellij.dvcs.repo.Repository
import com.intellij.dvcs.ui.DvcsBundle
import com.intellij.dvcs.ui.RepositoryChangesBrowserNode
import com.intellij.icons.AllIcons
@@ -653,32 +652,6 @@ internal object BranchesDashboardActions {
}
}
class CheckoutSelectedBranchAction : BranchesActionBase() {
override fun update(e: AnActionEvent, project: Project, branches: Collection<BranchInfo>) {
if (branches.size > 1) {
e.presentation.isEnabled = false
return
}
}
override fun actionPerformed(e: AnActionEvent) {
val project = e.project!!
val branch = e.getData(GIT_BRANCHES)!!.firstOrNull() ?: return
val controller = e.getData(BRANCHES_UI_CONTROLLER)!!
val repositories = controller.getSelectedRepositories(branch)
if (branch.isLocal) {
GitBranchPopupActions.LocalBranchActions.CheckoutAction
.checkoutBranch(project, repositories, branch.branchName)
}
else {
GitBranchPopupActions.RemoteBranchActions.CheckoutRemoteBranchAction
.checkoutRemoteBranch(project, repositories, branch.branchName)
}
}
}
class UpdateBranchFilterInLogAction : DumbAwareAction() {
override fun getActionUpdateThread(): ActionUpdateThread {