use of git4idea.repo.GitRemote in project intellij-community by JetBrains.
the class GitPull method displayDialog.
@Override
protected DialogState displayDialog(@NotNull Project project, @NotNull List<VirtualFile> gitRoots, @NotNull VirtualFile defaultRoot) {
final GitPullDialog dialog = new GitPullDialog(project, gitRoots, defaultRoot);
if (!dialog.showAndGet()) {
return null;
}
GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(project);
GitRepository repository = repositoryManager.getRepositoryForRoot(dialog.gitRoot());
assert repository != null : "Repository can't be null for root " + dialog.gitRoot();
String remoteOrUrl = dialog.getRemote();
if (remoteOrUrl == null) {
return null;
}
GitRemote remote = GitUtil.findRemoteByName(repository, remoteOrUrl);
final List<String> urls = remote == null ? Collections.singletonList(remoteOrUrl) : remote.getUrls();
Computable<GitLineHandler> handlerProvider = new Computable<GitLineHandler>() {
@Override
public GitLineHandler compute() {
return dialog.makeHandler(urls);
}
};
return new DialogState(dialog.gitRoot(), GitBundle.message("pulling.title", dialog.getRemote()), handlerProvider);
}
use of git4idea.repo.GitRemote in project intellij-community by JetBrains.
the class GitPushTarget method getFromPushSpec.
@Nullable
public static GitPushTarget getFromPushSpec(@NotNull GitRepository repository, @NotNull GitLocalBranch sourceBranch) {
final GitRemote remote = getRemoteToPush(repository, GitBranchUtil.getTrackInfoForBranch(repository, sourceBranch));
if (remote == null)
return null;
List<String> specs = remote.getPushRefSpecs();
if (specs.isEmpty())
return null;
String targetRef = GitPushSpecParser.getTargetRef(repository, sourceBranch.getName(), specs);
if (targetRef == null)
return null;
String remotePrefix = REFS_REMOTES_PREFIX + remote.getName() + "/";
if (targetRef.startsWith(remotePrefix)) {
targetRef = targetRef.substring(remotePrefix.length());
GitRemoteBranch remoteBranch = GitUtil.findOrCreateRemoteBranch(repository, remote, targetRef);
boolean existingBranch = repository.getBranches().getRemoteBranches().contains(remoteBranch);
return new GitPushTarget(remoteBranch, !existingBranch, false);
} else {
GitRemoteBranch remoteBranch = new GitSpecialRefRemoteBranch(targetRef, remote);
return new GitPushTarget(remoteBranch, true, true);
}
}
use of git4idea.repo.GitRemote in project intellij-community by JetBrains.
the class GitRefManager method groupForBranchFilter.
@NotNull
@Override
public List<RefGroup> groupForBranchFilter(@NotNull Collection<VcsRef> refs) {
List<RefGroup> simpleGroups = ContainerUtil.newArrayList();
List<VcsRef> localBranches = ContainerUtil.newArrayList();
List<VcsRef> trackedBranches = ContainerUtil.newArrayList();
MultiMap<GitRemote, VcsRef> remoteRefGroups = MultiMap.create();
MultiMap<VirtualFile, VcsRef> refsByRoot = groupRefsByRoot(refs);
for (Map.Entry<VirtualFile, Collection<VcsRef>> entry : refsByRoot.entrySet()) {
VirtualFile root = entry.getKey();
List<VcsRef> refsInRoot = ContainerUtil.sorted(entry.getValue(), myLabelsComparator);
GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
if (repository == null) {
LOG.warn("No repository for root: " + root);
continue;
}
Set<String> locals = getLocalBranches(repository);
Set<String> tracked = getTrackedRemoteBranches(repository);
Map<String, GitRemote> allRemote = getAllRemoteBranches(repository);
for (VcsRef ref : refsInRoot) {
if (ref.getType() == HEAD) {
simpleGroups.add(new SingletonRefGroup(ref));
continue;
}
String refName = ref.getName();
if (locals.contains(refName)) {
localBranches.add(ref);
} else if (allRemote.containsKey(refName)) {
remoteRefGroups.putValue(allRemote.get(refName), ref);
if (tracked.contains(refName)) {
trackedBranches.add(ref);
}
} else {
LOG.debug("Didn't find ref neither in local nor in remote branches: " + ref);
}
}
}
List<RefGroup> result = ContainerUtil.newArrayList();
result.addAll(simpleGroups);
if (!localBranches.isEmpty())
result.add(new LogicalRefGroup("Local", localBranches));
if (!trackedBranches.isEmpty())
result.add(new LogicalRefGroup("Tracked", trackedBranches));
for (Map.Entry<GitRemote, Collection<VcsRef>> entry : remoteRefGroups.entrySet()) {
final GitRemote remote = entry.getKey();
final Collection<VcsRef> branches = entry.getValue();
result.add(new RemoteRefGroup(remote, branches));
}
return result;
}
use of git4idea.repo.GitRemote 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.GitRemote 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