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