Git branches. Remove HEAD from the list of remotes; but still don't allow HEAD as new branch name.

This commit is contained in:
Kirill Likhodedov
2012-02-13 17:54:46 +04:00
parent 2f4df6f3cb
commit 0db26f748c
3 changed files with 17 additions and 7 deletions
+5 -3
View File
@@ -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<String> getBranchNames(@NotNull Collection<GitBranch> branches) {
public static Collection<String> getBranchNamesWithoutRemoteHead(@NotNull Collection<GitBranch> branches) {
Collection<String> names = new ArrayList<String>(branches.size());
for (GitBranch branch : branches) {
names.add(branch.getName());
if (!branch.isRemote() || !branch.getShortName().equals("HEAD")) {
names.add(branch.getName());
}
}
return names;
}
@@ -157,10 +157,10 @@ public class GitMultiRootBranchConfig {
GitBranchesCollection branchesCollection = repository.getBranches();
Collection<GitBranch> 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));
}
}
@@ -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<GitBranch> branches = local ? branchesCollection.getLocalBranches() : branchesCollection.getRemoteBranches();
if (!GitUtil.getBranchNames(branches).contains(inputString)) {
if (!GitUtil.getBranchNamesWithoutRemoteHead(branches).contains(inputString)) {
return false;
}
}