use of git4idea.GitRemoteBranch in project intellij-community by JetBrains.
the class GitRefManager method getAllRemoteBranches.
@NotNull
private static Map<String, GitRemote> getAllRemoteBranches(@NotNull GitRepository repository) {
Set<GitRemoteBranch> all = new HashSet<>(repository.getBranches().getRemoteBranches());
Map<String, GitRemote> allRemote = ContainerUtil.newHashMap();
for (GitRemoteBranch remoteBranch : all) {
allRemote.put(remoteBranch.getName(), remoteBranch.getRemote());
}
return allRemote;
}
use of git4idea.GitRemoteBranch in project intellij-community by JetBrains.
the class GitPushTarget method parse.
@NotNull
public static GitPushTarget parse(@NotNull GitRepository repository, @Nullable String remoteName, @NotNull String branchName) throws ParseException {
if (remoteName == null) {
throw new ParseException("No remotes defined", -1);
}
if (!GitRefNameValidator.getInstance().checkInput(branchName)) {
throw new ParseException("Invalid destination branch name: " + branchName, -1);
}
GitRemote remote = findRemote(repository.getRemotes(), remoteName);
if (remote == null) {
LOG.error("Remote [" + remoteName + "] is not found among " + repository.getRemotes());
throw new ParseException("Invalid remote: " + remoteName, -1);
}
GitRemoteBranch existingRemoteBranch = findRemoteBranch(repository, remote, branchName);
if (existingRemoteBranch != null) {
return new GitPushTarget(existingRemoteBranch, false);
}
GitRemoteBranch rb = new GitStandardRemoteBranch(remote, branchName);
return new GitPushTarget(rb, true);
}
use of git4idea.GitRemoteBranch in project intellij-community by JetBrains.
the class GitPullDialog method updateBranches.
private void updateBranches() {
final String selectedRemote = getRemote();
myBranchChooser.removeAllElements();
if (selectedRemote == null) {
return;
}
GitRepository repository = getRepository();
if (repository == null) {
return;
}
GitBranchTrackInfo trackInfo = GitUtil.getTrackInfoForCurrentBranch(repository);
GitRemoteBranch currentRemoteBranch = trackInfo == null ? null : trackInfo.getRemoteBranch();
List<GitRemoteBranch> remoteBranches = new ArrayList<>(repository.getBranches().getRemoteBranches());
Collections.sort(remoteBranches);
myBranchChooser.setElements(ContainerUtil.mapNotNull(remoteBranches, new Function<GitRemoteBranch, String>() {
@Override
public String fun(GitRemoteBranch branch) {
return branch.getRemote().getName().equals(selectedRemote) ? branch.getNameForLocalOperations() : null;
}
}), false);
if (currentRemoteBranch != null && currentRemoteBranch.getRemote().getName().equals(selectedRemote)) {
myBranchChooser.setElementMarked(currentRemoteBranch.getNameForLocalOperations(), true);
}
validateDialog();
}
use of git4idea.GitRemoteBranch in project intellij-community by JetBrains.
the class GitPushTargetTest method assertSpecialTargetRef.
private void assertSpecialTargetRef(@NotNull String expectedRefName, @NotNull String expectedRemoteName) {
GitPushTarget target = GitPushTarget.getFromPushSpec(myRepo, ObjectUtils.assertNotNull(myRepo.getCurrentBranch()));
assertNotNull(target);
assertTrue(target.isSpecialRef());
assertEquals(expectedRefName, target.getPresentation());
GitRemoteBranch remoteBranch = target.getBranch();
assertRemoteBranch(expectedRefName, expectedRefName, expectedRemoteName, remoteBranch);
}
use of git4idea.GitRemoteBranch in project intellij-community by JetBrains.
the class GitConfig method convertBranchConfig.
@Nullable
private static GitBranchTrackInfo convertBranchConfig(@Nullable BranchConfig branchConfig, @NotNull Collection<GitLocalBranch> localBranches, @NotNull Collection<GitRemoteBranch> remoteBranches) {
if (branchConfig == null) {
return null;
}
final String branchName = branchConfig.getName();
String remoteName = branchConfig.getBean().getRemote();
String mergeName = branchConfig.getBean().getMerge();
String rebaseName = branchConfig.getBean().getRebase();
if (StringUtil.isEmptyOrSpaces(mergeName) && StringUtil.isEmptyOrSpaces(rebaseName)) {
LOG.info("No branch." + branchName + ".merge/rebase item in the .git/config");
return null;
}
if (StringUtil.isEmptyOrSpaces(remoteName)) {
LOG.info("No branch." + branchName + ".remote item in the .git/config");
return null;
}
boolean merge = mergeName != null;
final String remoteBranchName = StringUtil.unquoteString(merge ? mergeName : rebaseName);
GitLocalBranch localBranch = findLocalBranch(branchName, localBranches);
GitRemoteBranch remoteBranch = findRemoteBranch(remoteBranchName, remoteName, remoteBranches);
if (localBranch == null || remoteBranch == null) {
// obsolete record in .git/config: local or remote branch doesn't exist, but the tracking information wasn't removed
LOG.debug("localBranch: " + localBranch + ", remoteBranch: " + remoteBranch);
return null;
}
return new GitBranchTrackInfo(localBranch, remoteBranch, merge);
}
Aggregations