Search in sources :

Example 1 with GitBranchesCollection

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;
}
Also used : Function(com.intellij.util.Function) GitBranchesCollection(git4idea.branch.GitBranchesCollection) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GitBranchesCollection

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;
}
Also used : GitRepository(git4idea.repo.GitRepository) GitBranchesCollection(git4idea.branch.GitBranchesCollection) GitBranch(git4idea.GitBranch)

Example 3 with GitBranchesCollection

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;
}
Also used : GitRepository(git4idea.repo.GitRepository) GitBranchesCollection(git4idea.branch.GitBranchesCollection)

Example 4 with GitBranchesCollection

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;
}
Also used : GitRepository(git4idea.repo.GitRepository) GitBranchesCollection(git4idea.branch.GitBranchesCollection) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with GitBranchesCollection

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitBranchesCollection(git4idea.branch.GitBranchesCollection) THashSet(gnu.trove.THashSet) OpenTHashSet(com.intellij.util.containers.OpenTHashSet) StopWatch(com.intellij.vcs.log.util.StopWatch) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GitBranchesCollection (git4idea.branch.GitBranchesCollection)5 GitRepository (git4idea.repo.GitRepository)3 NotNull (org.jetbrains.annotations.NotNull)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Function (com.intellij.util.Function)1 OpenTHashSet (com.intellij.util.containers.OpenTHashSet)1 StopWatch (com.intellij.vcs.log.util.StopWatch)1 GitBranch (git4idea.GitBranch)1 THashSet (gnu.trove.THashSet)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1