Search in sources :

Example 1 with GitRemoteBranch

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;
}
Also used : GitRemote(git4idea.repo.GitRemote) GitRemoteBranch(git4idea.GitRemoteBranch) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GitRemoteBranch

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);
}
Also used : GitRemote(git4idea.repo.GitRemote) GitStandardRemoteBranch(git4idea.GitStandardRemoteBranch) ParseException(java.text.ParseException) GitRemoteBranch(git4idea.GitRemoteBranch) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with GitRemoteBranch

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();
}
Also used : GitRepository(git4idea.repo.GitRepository) Function(com.intellij.util.Function) ArrayList(java.util.ArrayList) GitBranchTrackInfo(git4idea.repo.GitBranchTrackInfo) GitRemoteBranch(git4idea.GitRemoteBranch)

Example 4 with GitRemoteBranch

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);
}
Also used : GitRemoteBranch(git4idea.GitRemoteBranch)

Example 5 with GitRemoteBranch

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);
}
Also used : GitLocalBranch(git4idea.GitLocalBranch) GitRemoteBranch(git4idea.GitRemoteBranch) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GitRemoteBranch (git4idea.GitRemoteBranch)9 NotNull (org.jetbrains.annotations.NotNull)4 GitRemote (git4idea.repo.GitRemote)3 GitLocalBranch (git4idea.GitLocalBranch)2 GitBranchTrackInfo (git4idea.repo.GitBranchTrackInfo)2 Nullable (org.jetbrains.annotations.Nullable)2 Function (com.intellij.util.Function)1 GitStandardRemoteBranch (git4idea.GitStandardRemoteBranch)1 GitCommandResult (git4idea.commands.GitCommandResult)1 GitLineHandlerListener (git4idea.commands.GitLineHandlerListener)1 GitRepository (git4idea.repo.GitRepository)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1