From 0db26f748cb56ca20eed13ead5c66b08ff84d26b Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Mon, 13 Feb 2012 17:50:33 +0400 Subject: [PATCH] Git branches. Remove HEAD from the list of remotes; but still don't allow HEAD as new branch name. --- plugins/git4idea/src/git4idea/GitUtil.java | 8 +++++--- .../git4idea/ui/branch/GitMultiRootBranchConfig.java | 4 ++-- .../validators/GitNewBranchNameValidator.java | 12 ++++++++++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/plugins/git4idea/src/git4idea/GitUtil.java b/plugins/git4idea/src/git4idea/GitUtil.java index c49f36644ff4..841ca77aedfc 100644 --- a/plugins/git4idea/src/git4idea/GitUtil.java +++ b/plugins/git4idea/src/git4idea/GitUtil.java @@ -630,13 +630,15 @@ public class GitUtil { } /** - * Convert {@link GitBranch GitBranches} to their names. + * Convert {@link GitBranch GitBranches} to their names, and remove remote HEAD pointers. */ @NotNull - public static Collection getBranchNames(@NotNull Collection branches) { + public static Collection getBranchNamesWithoutRemoteHead(@NotNull Collection branches) { Collection names = new ArrayList(branches.size()); for (GitBranch branch : branches) { - names.add(branch.getName()); + if (!branch.isRemote() || !branch.getShortName().equals("HEAD")) { + names.add(branch.getName()); + } } return names; } diff --git a/plugins/git4idea/src/git4idea/ui/branch/GitMultiRootBranchConfig.java b/plugins/git4idea/src/git4idea/ui/branch/GitMultiRootBranchConfig.java index bc39ea6133de..6dbae288101c 100644 --- a/plugins/git4idea/src/git4idea/ui/branch/GitMultiRootBranchConfig.java +++ b/plugins/git4idea/src/git4idea/ui/branch/GitMultiRootBranchConfig.java @@ -157,10 +157,10 @@ public class GitMultiRootBranchConfig { GitBranchesCollection branchesCollection = repository.getBranches(); Collection branches = local ? branchesCollection.getLocalBranches() : branchesCollection.getRemoteBranches(); if (commonBranches == null) { - commonBranches = GitUtil.getBranchNames(branches); + commonBranches = GitUtil.getBranchNamesWithoutRemoteHead(branches); } else { - commonBranches.retainAll(GitUtil.getBranchNames(branches)); + commonBranches.retainAll(GitUtil.getBranchNamesWithoutRemoteHead(branches)); } } diff --git a/plugins/git4idea/src/git4idea/validators/GitNewBranchNameValidator.java b/plugins/git4idea/src/git4idea/validators/GitNewBranchNameValidator.java index 607e749b0208..8aade0efa526 100644 --- a/plugins/git4idea/src/git4idea/validators/GitNewBranchNameValidator.java +++ b/plugins/git4idea/src/git4idea/validators/GitNewBranchNameValidator.java @@ -60,13 +60,21 @@ public final class GitNewBranchNameValidator implements InputValidatorEx { } private boolean checkBranchConflict(String inputString) { - if (conflictsWithLocalBranch(inputString) || conflictsWithRemoteBranch(inputString)) { + if (isNotPermitted(inputString) || conflictsWithLocalBranch(inputString) || conflictsWithRemoteBranch(inputString)) { return false; } myErrorText = null; return true; } + private boolean isNotPermitted(@NotNull String inputString) { + if (inputString.equalsIgnoreCase("head")) { + myErrorText = "Branch name " + inputString + " is not valid"; + return true; + } + return false; + } + private boolean conflictsWithLocalBranch(String inputString) { return conflictsWithLocalOrRemote(inputString, true, " already exists"); } @@ -96,7 +104,7 @@ public final class GitNewBranchNameValidator implements InputValidatorEx { for (GitRepository repository : myRepositories) { GitBranchesCollection branchesCollection = repository.getBranches(); Collection branches = local ? branchesCollection.getLocalBranches() : branchesCollection.getRemoteBranches(); - if (!GitUtil.getBranchNames(branches).contains(inputString)) { + if (!GitUtil.getBranchNamesWithoutRemoteHead(branches).contains(inputString)) { return false; } }