use of git4idea.branch.GitBranchesCollection in project intellij-community by JetBrains.
the class GitTaskHandler method getAllBranches.
@NotNull
@Override
protected Iterable<TaskInfo> getAllBranches(@NotNull GitRepository repository) {
GitBranchesCollection branches = repository.getBranches();
List<TaskInfo> list = new ArrayList<>(ContainerUtil.map(branches.getLocalBranches(), (Function<GitBranch, TaskInfo>) branch -> new TaskInfo(branch.getName(), Collections.singleton(repository.getPresentableUrl()))));
list.addAll(ContainerUtil.map(branches.getRemoteBranches(), (Function<GitBranch, TaskInfo>) branch -> new TaskInfo(branch.getName(), Collections.singleton(repository.getPresentableUrl())) {
@Override
public boolean isRemote() {
return true;
}
}));
return list;
}
use of git4idea.branch.GitBranchesCollection 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.branch.GitBranchesCollection in project intellij-community by JetBrains.
the class GitNewBranchNameValidator method allReposHaveBranch.
private boolean allReposHaveBranch(String inputString, boolean local) {
for (GitRepository repository : myRepositories) {
GitBranchesCollection branchesCollection = repository.getBranches();
Collection<? extends GitBranch> branches = local ? branchesCollection.getLocalBranches() : branchesCollection.getRemoteBranches();
if (!GitBranchUtil.convertBranchesToNames(branches).contains(inputString)) {
return false;
}
}
return true;
}
use of git4idea.branch.GitBranchesCollection in project intellij-community by JetBrains.
the class GitTaskBranchesTest method initRepository.
@NotNull
@Override
protected Repository initRepository(@NotNull String name) {
String tempDirectory = FileUtil.getTempDirectory();
String root = tempDirectory + "/" + name;
assertTrue(new File(root).mkdirs());
GitRepository repository = GitTestUtil.createRepository(getProject(), root);
GitBranchesCollection branches = repository.getBranches();
assertEquals(1, branches.getLocalBranches().size());
return repository;
}
use of git4idea.branch.GitBranchesCollection in project intellij-community by JetBrains.
the class GitLogProvider method readBranches.
@NotNull
private Set<VcsRef> readBranches(@NotNull GitRepository repository) {
StopWatch sw = StopWatch.start("readBranches in " + repository.getRoot().getName());
VirtualFile root = repository.getRoot();
repository.update();
GitBranchesCollection branches = repository.getBranches();
Collection<GitLocalBranch> localBranches = branches.getLocalBranches();
Collection<GitRemoteBranch> remoteBranches = branches.getRemoteBranches();
Set<VcsRef> refs = new THashSet<>(localBranches.size() + remoteBranches.size());
for (GitLocalBranch localBranch : localBranches) {
Hash hash = branches.getHash(localBranch);
assert hash != null;
refs.add(myVcsObjectsFactory.createRef(hash, localBranch.getName(), GitRefManager.LOCAL_BRANCH, root));
}
for (GitRemoteBranch remoteBranch : remoteBranches) {
Hash hash = branches.getHash(remoteBranch);
assert hash != null;
refs.add(myVcsObjectsFactory.createRef(hash, remoteBranch.getNameForLocalOperations(), GitRefManager.REMOTE_BRANCH, root));
}
String currentRevision = repository.getCurrentRevision();
if (currentRevision != null) {
// null => fresh repository
refs.add(myVcsObjectsFactory.createRef(HashImpl.build(currentRevision), "HEAD", GitRefManager.HEAD, root));
}
sw.report();
return refs;
}
Aggregations