use of git4idea.GitBranch in project intellij-community by JetBrains.
the class DeepComparator method getRepositories.
@NotNull
private Map<GitRepository, GitBranch> getRepositories(@NotNull Map<VirtualFile, VcsLogProvider> providers, @NotNull String branchToCompare) {
Map<GitRepository, GitBranch> repos = ContainerUtil.newHashMap();
for (VirtualFile root : providers.keySet()) {
GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
if (repository == null || repository.getCurrentBranch() == null || repository.getBranches().findBranchByName(branchToCompare) == null) {
continue;
}
repos.put(repository, repository.getCurrentBranch());
}
return repos;
}
use of git4idea.GitBranch in project intellij-community by JetBrains.
the class GitNewBranchNameValidator method conflictsWithLocalOrRemote.
private boolean conflictsWithLocalOrRemote(@NotNull String inputString, boolean local, @NotNull String message) {
int conflictsWithCurrentName = 0;
for (GitRepository repository : myRepositories) {
if (inputString.equals(repository.getCurrentBranchName())) {
conflictsWithCurrentName++;
} else {
GitBranchesCollection branchesCollection = repository.getBranches();
Collection<? extends GitBranch> branches = local ? branchesCollection.getLocalBranches() : branchesCollection.getRemoteBranches();
for (GitBranch branch : branches) {
if (branch.getName().equals(inputString)) {
myErrorText = "Branch name " + inputString + message;
if (myRepositories.size() > 1 && !allReposHaveBranch(inputString, local)) {
myErrorText += " in repository " + repository.getPresentableUrl();
}
return true;
}
}
}
}
if (conflictsWithCurrentName == myRepositories.size()) {
myErrorText = "You are already on branch " + inputString;
return true;
}
return false;
}
use of git4idea.GitBranch in project intellij-community by JetBrains.
the class GitRebaseUpdater method getRemoteBranchToMerge.
@NotNull
private String getRemoteBranchToMerge() {
GitBranchPair gitBranchPair = myTrackedBranches.get(myRoot);
GitBranch dest = gitBranchPair.getDest();
LOG.assertTrue(dest != null, String.format("Destination branch is null for source branch %s in %s", gitBranchPair.getBranch().getName(), myRoot));
return dest.getName();
}
use of git4idea.GitBranch in project intellij-community by JetBrains.
the class GitRejectedPushUpdateDialog method makeDescription.
private String makeDescription() {
if (GitUtil.justOneGitRepository(myProject)) {
assert !myRepositories.isEmpty() : "repositories are empty";
GitRepository repository = myRepositories.iterator().next();
GitBranch currentBranch = getCurrentBranch(repository);
return DESCRIPTION_START + code(currentBranch.getName()) + " was rejected. <br/>" + descriptionEnding();
} else if (myRepositories.size() == 1) {
// there are more than 1 repositories in the project, but only one was rejected
GitRepository repository = myRepositories.iterator().next();
GitBranch currentBranch = getCurrentBranch(repository);
return DESCRIPTION_START + code(currentBranch.getName()) + " in repository <br/>" + code(repository.getPresentableUrl()) + " was rejected. <br/>" + descriptionEnding();
} else {
// several repositories rejected the push
Map<GitRepository, GitBranch> currentBranches = getCurrentBranches();
if (allBranchesHaveTheSameName(currentBranches)) {
String branchName = currentBranches.values().iterator().next().getName();
StringBuilder sb = new StringBuilder(DESCRIPTION_START + code(branchName) + " was rejected in repositories <br/>");
for (GitRepository repository : DvcsUtil.sortRepositories(currentBranches.keySet())) {
sb.append(HTML_IDENT).append(code(repository.getPresentableUrl())).append("<br/>");
}
sb.append(descriptionEnding());
return sb.toString();
} else {
StringBuilder sb = new StringBuilder("<html>Push of current branch was rejected: <br/>");
for (Map.Entry<GitRepository, GitBranch> entry : currentBranches.entrySet()) {
GitRepository repository = entry.getKey();
GitBranch currentBranch = entry.getValue();
sb.append(HTML_IDENT + code(currentBranch.getName()) + " in " + code(repository.getPresentableUrl()) + "<br/>");
}
sb.append(descriptionEnding());
return sb.toString();
}
}
}
use of git4idea.GitBranch in project intellij-community by JetBrains.
the class GitCompareWithBranchAction method getBranchNamesExceptCurrent.
@NotNull
@Override
protected List<String> getBranchNamesExceptCurrent(@NotNull GitRepository repository) {
List<GitBranch> localBranches = new ArrayList<>(repository.getBranches().getLocalBranches());
Collections.sort(localBranches);
List<GitBranch> remoteBranches = new ArrayList<>(repository.getBranches().getRemoteBranches());
Collections.sort(remoteBranches);
if (repository.isOnBranch()) {
localBranches.remove(repository.getCurrentBranch());
}
List<String> branchNames = ContainerUtil.newArrayList();
for (GitBranch branch : localBranches) {
branchNames.add(branch.getName());
}
for (GitBranch branch : remoteBranches) {
branchNames.add(branch.getName());
}
return branchNames;
}
Aggregations