mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[git] IDEA-132259 Allow to checkout remote branch as local if some of repositories are already on this branch
This commit is contained in:
@@ -24,6 +24,8 @@ import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import git4idea.GitBranch;
|
||||
import git4idea.branch.GitBranchUtil;
|
||||
import git4idea.branch.GitBrancher;
|
||||
@@ -282,25 +284,31 @@ class GitBranchPopupActions {
|
||||
@NotNull String remoteBranchName) {
|
||||
super("Checkout as new local branch");
|
||||
myProject = project;
|
||||
myRepositories = repositories;
|
||||
myRemoteBranchName = remoteBranchName;
|
||||
myRepositories = ContainerUtil.filter(repositories, new Condition<GitRepository>() {
|
||||
@Override
|
||||
public boolean value(GitRepository repository) {
|
||||
return !guessBranchName(myRemoteBranchName).equals(repository.getCurrentBranchName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final String name = Messages.showInputDialog(myProject, "Enter name of new branch", "Checkout Remote Branch", Messages.getQuestionIcon(),
|
||||
guessBranchName(), GitNewBranchNameValidator.newInstance(myRepositories));
|
||||
guessBranchName(myRemoteBranchName),
|
||||
GitNewBranchNameValidator.newInstance(myRepositories));
|
||||
if (name != null) {
|
||||
GitBrancher brancher = ServiceManager.getService(myProject, GitBrancher.class);
|
||||
brancher.checkoutNewBranchStartingFrom(name, myRemoteBranchName, myRepositories, null);
|
||||
}
|
||||
}
|
||||
|
||||
private String guessBranchName() {
|
||||
private static String guessBranchName(@NotNull String remoteBranchName) {
|
||||
// TODO: check if we already have a branch with that name; check if that branch tracks this remote branch. Show different messages
|
||||
int slashPosition = myRemoteBranchName.indexOf("/");
|
||||
int slashPosition = remoteBranchName.indexOf("/");
|
||||
// if no slash is found (for example, in the case of git-svn remote branches), propose the whole name.
|
||||
return myRemoteBranchName.substring(slashPosition+1);
|
||||
return remoteBranchName.substring(slashPosition + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user