Search in sources :

Example 1 with GitLocalBranch

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

the class GitCherryPicker method getInfo.

@Override
public String getInfo(@NotNull VcsLog log, @NotNull Map<VirtualFile, List<Hash>> commits) {
    int commitsNum = commits.values().size();
    for (VirtualFile root : commits.keySet()) {
        // all these roots already related to this cherry-picker
        GitRepository repository = ObjectUtils.assertNotNull(myRepositoryManager.getRepositoryForRoot(root));
        for (Hash commit : commits.get(root)) {
            GitLocalBranch currentBranch = repository.getCurrentBranch();
            Collection<String> containingBranches = log.getContainingBranches(commit, root);
            if (currentBranch != null && containingBranches != null && containingBranches.contains(currentBranch.getName())) {
                // already in the current branch
                return String.format("The current branch already contains %s the selected %s", commitsNum > 1 ? "one of" : "", pluralize("commit", commitsNum));
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRepository(git4idea.repo.GitRepository) GitLocalBranch(git4idea.GitLocalBranch) Hash(com.intellij.vcs.log.Hash)

Example 2 with GitLocalBranch

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

the class GitOutgoingCommitsProvider method getOutgoingCommits.

@NotNull
@Override
public OutgoingResult getOutgoingCommits(@NotNull GitRepository repository, @NotNull PushSpec<GitPushSource, GitPushTarget> pushSpec, boolean initial) {
    GitLocalBranch branch = pushSpec.getSource().getBranch();
    String source = branch.equals(repository.getCurrentBranch()) ? HEAD : branch.getFullName();
    GitPushTarget target = pushSpec.getTarget();
    String destination = target.getBranch().getFullName();
    try {
        List<GitCommit> commits;
        if (!target.isNewBranchCreated()) {
            commits = GitHistoryUtils.history(myProject, repository.getRoot(), destination + ".." + source);
        } else {
            commits = GitHistoryUtils.history(myProject, repository.getRoot(), source, "--not", "--remotes=" + target.getBranch().getRemote().getName(), "--max-count=" + 1000);
        }
        return new OutgoingResult(commits, Collections.<VcsError>emptyList());
    } catch (VcsException e) {
        return new OutgoingResult(Collections.<VcsFullCommitDetails>emptyList(), Collections.singletonList(new VcsError(GitUtil.cleanupErrorPrefixes(e.getMessage()))));
    }
}
Also used : GitLocalBranch(git4idea.GitLocalBranch) GitCommit(git4idea.GitCommit) VcsException(com.intellij.openapi.vcs.VcsException) OutgoingResult(com.intellij.dvcs.push.OutgoingResult) VcsFullCommitDetails(com.intellij.vcs.log.VcsFullCommitDetails) VcsError(com.intellij.dvcs.push.VcsError) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with GitLocalBranch

use of git4idea.GitLocalBranch 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 4 with GitLocalBranch

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

the class GithubShareAction method pushCurrentBranch.

private static boolean pushCurrentBranch(@NotNull Project project, @NotNull GitRepository repository, @NotNull String remoteName, @NotNull String remoteUrl, @NotNull String name, @NotNull String url) {
    Git git = ServiceManager.getService(Git.class);
    GitLocalBranch currentBranch = repository.getCurrentBranch();
    if (currentBranch == null) {
        GithubNotifications.showErrorURL(project, "Can't finish GitHub sharing process", "Successfully created project ", "'" + name + "'", " on GitHub, but initial push failed: no current branch", url);
        return false;
    }
    GitCommandResult result = git.push(repository, remoteName, remoteUrl, currentBranch.getName(), true);
    if (!result.success()) {
        GithubNotifications.showErrorURL(project, "Can't finish GitHub sharing process", "Successfully created project ", "'" + name + "'", " on GitHub, but initial push failed:<br/>" + result.getErrorOutputAsHtmlString(), url);
        return false;
    }
    return true;
}
Also used : GitLocalBranch(git4idea.GitLocalBranch)

Example 5 with GitLocalBranch

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

Aggregations

GitLocalBranch (git4idea.GitLocalBranch)10 GitRepository (git4idea.repo.GitRepository)5 NotNull (org.jetbrains.annotations.NotNull)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 GitRemoteBranch (git4idea.GitRemoteBranch)2 GitBranchTrackInfo (git4idea.repo.GitBranchTrackInfo)2 GitRemote (git4idea.repo.GitRemote)2 Nullable (org.jetbrains.annotations.Nullable)2 OutgoingResult (com.intellij.dvcs.push.OutgoingResult)1 VcsError (com.intellij.dvcs.push.VcsError)1 Condition (com.intellij.openapi.util.Condition)1 VcsException (com.intellij.openapi.vcs.VcsException)1 Hash (com.intellij.vcs.log.Hash)1 VcsFullCommitDetails (com.intellij.vcs.log.VcsFullCommitDetails)1 GitCommit (git4idea.GitCommit)1 GitBranchPair (git4idea.branch.GitBranchPair)1 Git (git4idea.commands.Git)1 GitCommandResult (git4idea.commands.GitCommandResult)1 GitLineHandlerListener (git4idea.commands.GitLineHandlerListener)1 IOException (java.io.IOException)1