Search in sources :

Example 6 with GitRemote

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

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

the class GitPullDialog method updateRemotes.

private void updateRemotes() {
    GitRepository repository = getRepository();
    if (repository == null) {
        return;
    }
    GitRemote currentRemote = getCurrentOrDefaultRemote(repository);
    myRemote.setRenderer(getGitRemoteListCellRenderer(currentRemote != null ? currentRemote.getName() : null));
    myRemote.removeAllItems();
    for (GitRemote remote : repository.getRemotes()) {
        myRemote.addItem(remote);
    }
    myRemote.setSelectedItem(currentRemote);
}
Also used : GitRemote(git4idea.repo.GitRemote) GitRepository(git4idea.repo.GitRepository)

Example 8 with GitRemote

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

the class GitRebaseDialog method updateTrackedBranch.

/**
   * Update tracked branch basing on the currently selected branch
   */
private void updateTrackedBranch() {
    try {
        final VirtualFile root = gitRoot();
        String currentBranch = (String) myBranchComboBox.getSelectedItem();
        GitBranch trackedBranch = null;
        if (currentBranch != null) {
            String remote = GitConfigUtil.getValue(myProject, root, "branch." + currentBranch + ".remote");
            String mergeBranch = GitConfigUtil.getValue(myProject, root, "branch." + currentBranch + ".merge");
            if (remote == null || mergeBranch == null) {
                trackedBranch = null;
            } else {
                mergeBranch = GitBranchUtil.stripRefsPrefix(mergeBranch);
                if (remote.equals(".")) {
                    trackedBranch = new GitSvnRemoteBranch(mergeBranch);
                } else {
                    GitRemote r = GitBranchUtil.findRemoteByNameOrLogError(myProject, root, remote);
                    if (r != null) {
                        trackedBranch = new GitStandardRemoteBranch(r, mergeBranch);
                    }
                }
            }
        }
        if (trackedBranch != null) {
            myOntoComboBox.setSelectedItem(trackedBranch);
        } else {
            GitUIUtil.getTextField(myOntoComboBox).setText("");
        }
        GitUIUtil.getTextField(myFromComboBox).setText("");
    } catch (VcsException e) {
        GitUIUtil.showOperationError(myProject, e, "git config");
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRemote(git4idea.repo.GitRemote) VcsException(com.intellij.openapi.vcs.VcsException)

Example 9 with GitRemote

use of git4idea.repo.GitRemote 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 10 with GitRemote

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

the class GitFetcher method fetch.

@NotNull
public GitFetchResult fetch(@NotNull VirtualFile root, @NotNull String remoteName, @Nullable String branch) {
    GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
    if (repository == null) {
        return logError("Repository can't be null for " + root, myRepositoryManager.toString());
    }
    GitRemote remote = GitUtil.findRemoteByName(repository, remoteName);
    if (remote == null) {
        return logError("Couldn't find remote with the name " + remoteName, null);
    }
    return fetchRemote(repository, remote, branch);
}
Also used : GitRemote(git4idea.repo.GitRemote) GitRepository(git4idea.repo.GitRepository) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GitRemote (git4idea.repo.GitRemote)22 NotNull (org.jetbrains.annotations.NotNull)8 GitRepository (git4idea.repo.GitRepository)7 Nullable (org.jetbrains.annotations.Nullable)7 GitRemoteBranch (git4idea.GitRemoteBranch)3 GitBranchTrackInfo (git4idea.repo.GitBranchTrackInfo)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 SimpleRefGroup (com.intellij.vcs.log.impl.SimpleRefGroup)2 GitLocalBranch (git4idea.GitLocalBranch)2 GitStandardRemoteBranch (git4idea.GitStandardRemoteBranch)2 Computable (com.intellij.openapi.util.Computable)1 VcsException (com.intellij.openapi.vcs.VcsException)1 MultiMap (com.intellij.util.containers.MultiMap)1 SingletonRefGroup (com.intellij.vcs.log.impl.SingletonRefGroup)1 Git (git4idea.commands.Git)1 GitCommandResult (git4idea.commands.GitCommandResult)1 GitCompoundResult (git4idea.commands.GitCompoundResult)1 GitLineHandler (git4idea.commands.GitLineHandler)1 GitPullDialog (git4idea.merge.GitPullDialog)1 GitRepositoryManager (git4idea.repo.GitRepositoryManager)1