Search in sources :

Example 6 with GitBranchTrackInfo

use of git4idea.repo.GitBranchTrackInfo in project intellij-community by JetBrains.

the class GitRefManager method createTrackedGroup.

@Nullable
private static SimpleRefGroup createTrackedGroup(@NotNull GitRepository repository, @NotNull Collection<VcsRef> references, @NotNull VcsRef localRef) {
    List<VcsRef> remoteBranches = ContainerUtil.filter(references, ref -> ref.getType().equals(REMOTE_BRANCH));
    GitBranchTrackInfo trackInfo = ContainerUtil.find(repository.getBranchTrackInfos(), info -> info.getLocalBranch().getName().equals(localRef.getName()));
    if (trackInfo != null) {
        VcsRef trackedRef = ContainerUtil.find(remoteBranches, ref -> ref.getName().equals(trackInfo.getRemoteBranch().getName()));
        if (trackedRef != null) {
            return new SimpleRefGroup(trackInfo.getRemote().getName() + REMOTE_TABLE_SEPARATOR + localRef.getName(), ContainerUtil.newArrayList(localRef, trackedRef));
        }
    }
    List<VcsRef> trackingCandidates = ContainerUtil.filter(remoteBranches, ref -> ref.getName().endsWith(SEPARATOR + localRef.getName()));
    for (GitRemote remote : repository.getRemotes()) {
        for (VcsRef candidate : trackingCandidates) {
            if (candidate.getName().equals(remote.getName() + SEPARATOR + localRef.getName())) {
                return new SimpleRefGroup(remote.getName() + REMOTE_TABLE_SEPARATOR + localRef.getName(), ContainerUtil.newArrayList(localRef, candidate));
            }
        }
    }
    return null;
}
Also used : GitRemote(git4idea.repo.GitRemote) GitBranchTrackInfo(git4idea.repo.GitBranchTrackInfo) SimpleRefGroup(com.intellij.vcs.log.impl.SimpleRefGroup) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with GitBranchTrackInfo

use of git4idea.repo.GitBranchTrackInfo in project intellij-community by JetBrains.

the class GitPullDialog method getCurrentOrDefaultRemote.

/**
   * If the current branch is a tracking branch, returns its remote.
   * Otherwise tries to guess: if there is origin, returns origin, otherwise returns the first remote in the list.
   */
@Nullable
private static GitRemote getCurrentOrDefaultRemote(@NotNull GitRepository repository) {
    Collection<GitRemote> remotes = repository.getRemotes();
    if (remotes.isEmpty()) {
        return null;
    }
    GitBranchTrackInfo trackInfo = GitUtil.getTrackInfoForCurrentBranch(repository);
    if (trackInfo != null) {
        return trackInfo.getRemote();
    } else {
        GitRemote origin = GitUtil.getDefaultRemote(remotes);
        if (origin != null) {
            return origin;
        } else {
            return remotes.iterator().next();
        }
    }
}
Also used : GitRemote(git4idea.repo.GitRemote) GitBranchTrackInfo(git4idea.repo.GitBranchTrackInfo) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GitBranchTrackInfo (git4idea.repo.GitBranchTrackInfo)7 GitRemote (git4idea.repo.GitRemote)3 Nullable (org.jetbrains.annotations.Nullable)3 GitLocalBranch (git4idea.GitLocalBranch)2 GitRemoteBranch (git4idea.GitRemoteBranch)2 GitRepository (git4idea.repo.GitRepository)2 NotNull (org.jetbrains.annotations.NotNull)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Function (com.intellij.util.Function)1 SimpleRefGroup (com.intellij.vcs.log.impl.SimpleRefGroup)1 GitBranchPair (git4idea.branch.GitBranchPair)1 ArrayList (java.util.ArrayList)1