diff --git a/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopup.java b/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopup.java index 30f02e80538d..747ead0b1614 100644 --- a/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopup.java +++ b/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopup.java @@ -122,11 +122,19 @@ class GitBranchPopup extends DvcsBranchPopup { popupGroup.addAll(createRepositoriesActions()); popupGroup.addSeparator("Common Local Branches"); - List localBranchActions = - myMultiRootBranchConfig.getLocalBranchNames().stream().map(l -> createLocalBranchActions(allRepositories, l)).filter(Objects::nonNull) - .collect(toList()); - wrapWithMoreActionIfNeeded(myProject, popupGroup, ContainerUtil.sorted(localBranchActions, FAVORITE_BRANCH_COMPARATOR), - getNumOfTopShownBranches(localBranchActions), SHOW_ALL_LOCALS_KEY, true); + List localBranchActions = myMultiRootBranchConfig.getLocalBranchNames().stream() + .map(l -> createLocalBranchActions(allRepositories, l)) + .filter(Objects::nonNull) + .sorted(FAVORITE_BRANCH_COMPARATOR) + .collect(toList()); + int topShownBranches = getNumOfTopShownBranches(localBranchActions); + String currentBranch = myMultiRootBranchConfig.getCurrentBranch(); + if (currentBranch != null) { + localBranchActions + .add(0, new GitBranchPopupActions.CurrentBranchActions(myProject, allRepositories, currentBranch, myCurrentRepository)); + topShownBranches++; + } + wrapWithMoreActionIfNeeded(myProject, popupGroup, localBranchActions, topShownBranches, SHOW_ALL_LOCALS_KEY, true); popupGroup.addSeparator("Common Remote Branches"); List remoteBranchActions = map(((GitMultiRootBranchConfig)myMultiRootBranchConfig).getRemoteBranches(), diff --git a/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopupActions.java b/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopupActions.java index 3aff81024041..f7488605b70c 100644 --- a/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopupActions.java +++ b/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopupActions.java @@ -27,6 +27,7 @@ import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.util.containers.ContainerUtil; +import git4idea.GitLocalBranch; import git4idea.branch.GitBranchUtil; import git4idea.branch.GitBrancher; import git4idea.branch.GitNewBranchOptions; @@ -74,15 +75,21 @@ class GitBranchPopupActions { } popupGroup.addSeparator("Local Branches" + repoInfo); - List localBranchActions = - myRepository.getBranches().getLocalBranches().stream() - .sorted() - .filter(branch -> !branch.equals(myRepository.getCurrentBranch())) - .map(branch -> new LocalBranchActions(myProject, repositoryList, branch.getName(), myRepository)) - .collect(toList()); + GitLocalBranch currentBranch = myRepository.getCurrentBranch(); + List localBranchActions = myRepository.getBranches().getLocalBranches().stream() + .sorted() + .filter(branch -> !branch.equals(currentBranch)) + .map(branch -> new LocalBranchActions(myProject, repositoryList, branch.getName(), myRepository)) + .sorted(FAVORITE_BRANCH_COMPARATOR) + .collect(toList()); + int topShownBranches = getNumOfTopShownBranches(localBranchActions); + if (currentBranch != null) { + localBranchActions.add(0, new CurrentBranchActions(myProject, repositoryList, currentBranch.getName(), myRepository)); + topShownBranches++; + } // if there are only a few local favorites -> show all; for remotes it's better to show only favorites; - wrapWithMoreActionIfNeeded(myProject, popupGroup, ContainerUtil.sorted(localBranchActions, FAVORITE_BRANCH_COMPARATOR), - getNumOfTopShownBranches(localBranchActions), firstLevelGroup ? GitBranchPopup.SHOW_ALL_LOCALS_KEY : null, + wrapWithMoreActionIfNeeded(myProject, popupGroup, localBranchActions, + topShownBranches, firstLevelGroup ? GitBranchPopup.SHOW_ALL_LOCALS_KEY : null, firstLevelGroup); popupGroup.addSeparator("Remote Branches" + repoInfo); @@ -160,9 +167,9 @@ class GitBranchPopupActions { */ static class LocalBranchActions extends BranchActionGroup implements PopupElementWithAdditionalInfo { - private final Project myProject; - private final List myRepositories; - private final String myBranchName; + protected final Project myProject; + protected final List myRepositories; + protected final String myBranchName; @NotNull private final GitRepository mySelectedRepository; private final GitBranchManager myGitBranchManager; @@ -310,6 +317,21 @@ class GitBranchPopupActions { } } + static class CurrentBranchActions extends LocalBranchActions { + CurrentBranchActions(@NotNull Project project, + @NotNull List repositories, + @NotNull String branchName, + @NotNull GitRepository selectedRepository) { + super(project, repositories, branchName, selectedRepository); + } + + @NotNull + @Override + public AnAction[] getChildren(@Nullable AnActionEvent e) { + return new AnAction[]{new LocalBranchActions.RenameBranchAction(myProject, myRepositories, myBranchName)}; + } + } + /** * Actions available for remote branches */