Search in sources :

Example 1 with GitBranchPair

use of git4idea.branch.GitBranchPair in project intellij-community by JetBrains.

the class GitMergeUpdater method isSaveNeeded.

@Override
public boolean isSaveNeeded() {
    try {
        if (GitUtil.hasLocalChanges(true, myProject, myRoot)) {
            return true;
        }
    } catch (VcsException e) {
        LOG.info("isSaveNeeded failed to check staging area", e);
        return true;
    }
    // git log --name-status master..origin/master
    GitBranchPair gitBranchPair = myTrackedBranches.get(myRoot);
    String currentBranch = gitBranchPair.getBranch().getName();
    String remoteBranch = gitBranchPair.getDest().getName();
    try {
        GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(myRoot);
        if (repository == null) {
            LOG.error("Repository is null for root " + myRoot);
            // fail safe
            return true;
        }
        final Collection<String> remotelyChanged = GitUtil.getPathsDiffBetweenRefs(Git.getInstance(), repository, currentBranch, remoteBranch);
        final List<File> locallyChanged = myChangeListManager.getAffectedPaths();
        for (final File localPath : locallyChanged) {
            if (ContainerUtil.exists(remotelyChanged, new Condition<String>() {

                @Override
                public boolean value(String remotelyChangedPath) {
                    return FileUtil.pathsEqual(localPath.getPath(), remotelyChangedPath);
                }
            })) {
                // found a file which was changed locally and remotely => need to save
                return true;
            }
        }
        return false;
    } catch (VcsException e) {
        LOG.info("failed to get remotely changed files for " + currentBranch + ".." + remoteBranch, e);
        // fail safe
        return true;
    }
}
Also used : GitRepository(git4idea.repo.GitRepository) GitBranchPair(git4idea.branch.GitBranchPair) VcsException(com.intellij.openapi.vcs.VcsException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 2 with GitBranchPair

use of git4idea.branch.GitBranchPair in project intellij-community by JetBrains.

the class GitRebaseUpdater method getRemoteBranchToMerge.

@NotNull
private String getRemoteBranchToMerge() {
    GitBranchPair gitBranchPair = myTrackedBranches.get(myRoot);
    GitBranch dest = gitBranchPair.getDest();
    LOG.assertTrue(dest != null, String.format("Destination branch is null for source branch %s in %s", gitBranchPair.getBranch().getName(), myRoot));
    return dest.getName();
}
Also used : GitBranchPair(git4idea.branch.GitBranchPair) GitBranch(git4idea.GitBranch) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with GitBranchPair

use of git4idea.branch.GitBranchPair 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

GitBranchPair (git4idea.branch.GitBranchPair)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 GitRepository (git4idea.repo.GitRepository)2 VcsException (com.intellij.openapi.vcs.VcsException)1 GitBranch (git4idea.GitBranch)1 GitLocalBranch (git4idea.GitLocalBranch)1 GitBranchTrackInfo (git4idea.repo.GitBranchTrackInfo)1 File (java.io.File)1 NotNull (org.jetbrains.annotations.NotNull)1