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;
}
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();
}
}
}
Aggregations