Search in sources :

Example 6 with GitRemoteBranch

use of git4idea.GitRemoteBranch in project intellij-community by JetBrains.

the class GitPushOperation method doPush.

@NotNull
private ResultWithOutput doPush(@NotNull GitRepository repository, @NotNull PushSpec<GitPushSource, GitPushTarget> pushSpec) {
    GitPushTarget target = pushSpec.getTarget();
    GitLocalBranch sourceBranch = pushSpec.getSource().getBranch();
    GitRemoteBranch targetBranch = target.getBranch();
    GitLineHandlerListener progressListener = GitStandardProgressAnalyzer.createListener(myProgressIndicator);
    boolean setUpstream = pushSpec.getTarget().isNewBranchCreated() && !branchTrackingInfoIsSet(repository, sourceBranch);
    String tagMode = myTagMode == null ? null : myTagMode.getArgument();
    String spec = sourceBranch.getFullName() + ":" + targetBranch.getNameForRemoteOperations();
    GitCommandResult res = myGit.push(repository, targetBranch.getRemote(), spec, myForce, setUpstream, tagMode, progressListener);
    return new ResultWithOutput(res);
}
Also used : GitLocalBranch(git4idea.GitLocalBranch) GitLineHandlerListener(git4idea.commands.GitLineHandlerListener) GitCommandResult(git4idea.commands.GitCommandResult) GitRemoteBranch(git4idea.GitRemoteBranch) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with GitRemoteBranch

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

Example 8 with GitRemoteBranch

use of git4idea.GitRemoteBranch in project intellij-community by JetBrains.

the class GitRefManager method getTrackedRemoteBranches.

@NotNull
private static Set<String> getTrackedRemoteBranches(@NotNull GitRepository repository) {
    Set<GitRemoteBranch> all = new HashSet<>(repository.getBranches().getRemoteBranches());
    Set<String> tracked = new HashSet<>();
    for (GitBranchTrackInfo info : repository.getBranchTrackInfos()) {
        GitRemoteBranch trackedRemoteBranch = info.getRemoteBranch();
        if (all.contains(trackedRemoteBranch)) {
            // check that this branch really exists, not just written in .git/config
            tracked.add(trackedRemoteBranch.getName());
        }
    }
    return tracked;
}
Also used : GitBranchTrackInfo(git4idea.repo.GitBranchTrackInfo) GitRemoteBranch(git4idea.GitRemoteBranch) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with GitRemoteBranch

use of git4idea.GitRemoteBranch in project intellij-community by JetBrains.

the class GitPushTargetTest method assertStandardRemoteBranch.

private void assertStandardRemoteBranch(@NotNull String expectedPresentation, @NotNull GitBranch expectedBranch) {
    GitPushTarget target = GitPushTarget.getFromPushSpec(myRepo, ObjectUtils.assertNotNull(myRepo.getCurrentBranch()));
    assertNotNull(target);
    assertFalse(target.isSpecialRef());
    assertEquals(expectedPresentation, target.getPresentation());
    GitRemoteBranch remoteBranch = target.getBranch();
    assertEquals(expectedBranch, remoteBranch);
}
Also used : GitRemoteBranch(git4idea.GitRemoteBranch)

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