mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Git branches. Remove HEAD from the list of remotes; but still don't allow HEAD as new branch name.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user