Search in sources :

Example 1 with GitBranchTrackInfo

use of git4idea.repo.GitBranchTrackInfo 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 2 with GitBranchTrackInfo

use of git4idea.repo.GitBranchTrackInfo in project intellij-community by JetBrains.

the class GitFetcher method getFetchParams.

@NotNull
private static FetchParams getFetchParams(@NotNull GitRepository repository) {
    GitLocalBranch currentBranch = repository.getCurrentBranch();
    if (currentBranch == null) {
        // fetching current branch is called from Update Project and Push, where branch tracking is pre-checked
        String message = "Current branch can't be null here. \nRepository: " + repository;
        LOG.error(message);
        return new FetchParams(GitFetchResult.error(new Exception(message)));
    }
    GitBranchTrackInfo trackInfo = GitBranchUtil.getTrackInfoForBranch(repository, currentBranch);
    if (trackInfo == null) {
        String message = "Tracked info is null for branch " + currentBranch + "\n Repository: " + repository;
        LOG.error(message);
        return new FetchParams(GitFetchResult.error(new Exception(message)));
    }
    GitRemote remote = trackInfo.getRemote();
    return new FetchParams(remote, trackInfo.getRemoteBranch());
}
Also used : GitRemote(git4idea.repo.GitRemote) GitLocalBranch(git4idea.GitLocalBranch) GitBranchTrackInfo(git4idea.repo.GitBranchTrackInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with GitBranchTrackInfo

use of git4idea.repo.GitBranchTrackInfo in project intellij-community by JetBrains.

the class GitUpdateProcess method checkTrackedBranchesConfigured.

/**
   * For each root check that the repository is on branch, and this branch is tracking a remote branch,
   * and the remote branch exists.
   * If it is not true for at least one of roots, notify and return false.
   * If branch configuration is OK for all roots, return true.
   */
private boolean checkTrackedBranchesConfigured() {
    LOG.info("checking tracked branch configuration...");
    for (GitRepository repository : myRepositories) {
        VirtualFile root = repository.getRoot();
        final GitLocalBranch branch = repository.getCurrentBranch();
        if (branch == null) {
            LOG.info("checkTrackedBranchesConfigured: current branch is null in " + repository);
            notifyImportantError(myProject, "Can't update: no current branch", "You are in 'detached HEAD' state, which means that you're not on any branch" + rootStringIfNeeded(root) + "Checkout a branch to make update possible.");
            return false;
        }
        GitBranchTrackInfo trackInfo = GitBranchUtil.getTrackInfoForBranch(repository, branch);
        if (trackInfo == null) {
            final String branchName = branch.getName();
            LOG.info(String.format("checkTrackedBranchesConfigured: no track info for current branch %s in %s", branch, repository));
            String recommendedCommand = String.format(GitVersionSpecialty.KNOWS_SET_UPSTREAM_TO.existsIn(repository.getVcs().getVersion()) ? "git branch --set-upstream-to origin/%1$s %1$s" : "git branch --set-upstream %1$s origin/%1$s", branchName);
            notifyImportantError(myProject, "Can't update: no tracked branch", "No tracked branch configured for branch " + code(branchName) + rootStringIfNeeded(root) + "To make your branch track a remote branch call, for example,<br/>" + "<code>" + recommendedCommand + "</code>");
            return false;
        }
        myTrackedBranches.put(root, new GitBranchPair(branch, trackInfo.getRemoteBranch()));
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRepository(git4idea.repo.GitRepository) GitLocalBranch(git4idea.GitLocalBranch) GitBranchPair(git4idea.branch.GitBranchPair) GitBranchTrackInfo(git4idea.repo.GitBranchTrackInfo)

Example 4 with GitBranchTrackInfo

use of git4idea.repo.GitBranchTrackInfo in project intellij-community by JetBrains.

the class GitPushSupport method getDefaultTarget.

@Nullable
@Override
public GitPushTarget getDefaultTarget(@NotNull GitRepository repository) {
    if (repository.isFresh()) {
        return null;
    }
    GitLocalBranch currentBranch = repository.getCurrentBranch();
    if (currentBranch == null) {
        return null;
    }
    GitPushTarget persistedTarget = getPersistedTarget(repository, currentBranch);
    if (persistedTarget != null) {
        return persistedTarget;
    }
    GitPushTarget pushSpecTarget = GitPushTarget.getFromPushSpec(repository, currentBranch);
    if (pushSpecTarget != null) {
        return pushSpecTarget;
    }
    GitBranchTrackInfo trackInfo = GitBranchUtil.getTrackInfoForBranch(repository, currentBranch);
    if (trackInfo != null) {
        return new GitPushTarget(trackInfo.getRemoteBranch(), false);
    }
    return proposeTargetForNewBranch(repository, currentBranch);
}
Also used : GitBranchTrackInfo(git4idea.repo.GitBranchTrackInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with GitBranchTrackInfo

use of git4idea.repo.GitBranchTrackInfo 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)

Aggregations

GitBranchTrackInfo (git4idea.repo.GitBranchTrackInfo)7 GitRemote (git4idea.repo.GitRemote)3 Nullable (org.jetbrains.annotations.Nullable)3 GitLocalBranch (git4idea.GitLocalBranch)2 GitRemoteBranch (git4idea.GitRemoteBranch)2 GitRepository (git4idea.repo.GitRepository)2 NotNull (org.jetbrains.annotations.NotNull)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Function (com.intellij.util.Function)1 SimpleRefGroup (com.intellij.vcs.log.impl.SimpleRefGroup)1 GitBranchPair (git4idea.branch.GitBranchPair)1 ArrayList (java.util.ArrayList)1