Search in sources :

Example 1 with GitUpdateResult

use of git4idea.update.GitUpdateResult in project intellij-community by JetBrains.

the class GitPushOperation method prepareCombinedResult.

private GitPushResult prepareCombinedResult(final Map<GitRepository, GitPushRepoResult> allRoots, final Map<GitRepository, GitUpdateResult> updatedRoots, final Map<GitRepository, String> preUpdatePositions, Label beforeUpdateLabel, Label afterUpdateLabel) {
    Map<GitRepository, GitPushRepoResult> results = ContainerUtil.newHashMap();
    UpdatedFiles updatedFiles = UpdatedFiles.create();
    for (Map.Entry<GitRepository, GitPushRepoResult> entry : allRoots.entrySet()) {
        GitRepository repository = entry.getKey();
        GitPushRepoResult simpleResult = entry.getValue();
        GitUpdateResult updateResult = updatedRoots.get(repository);
        if (updateResult == null) {
            results.put(repository, simpleResult);
        } else {
            collectUpdatedFiles(updatedFiles, repository, preUpdatePositions.get(repository));
            results.put(repository, GitPushRepoResult.addUpdateResult(simpleResult, updateResult));
        }
    }
    return new GitPushResult(results, updatedFiles, beforeUpdateLabel, afterUpdateLabel);
}
Also used : GitRepository(git4idea.repo.GitRepository) GitUpdateResult(git4idea.update.GitUpdateResult) UpdatedFiles(com.intellij.openapi.vcs.update.UpdatedFiles)

Example 2 with GitUpdateResult

use of git4idea.update.GitUpdateResult in project intellij-community by JetBrains.

the class GitPushOperation method execute.

@NotNull
public GitPushResult execute() {
    PushUpdateSettings updateSettings = readPushUpdateSettings();
    Label beforePushLabel = null;
    Label afterPushLabel = null;
    Map<GitRepository, String> preUpdatePositions = updateRootInfoAndRememberPositions();
    Boolean rebaseOverMergeProblemDetected = null;
    final Map<GitRepository, GitPushRepoResult> results = ContainerUtil.newHashMap();
    Map<GitRepository, GitUpdateResult> updatedRoots = ContainerUtil.newHashMap();
    try {
        Collection<GitRepository> remainingRoots = myPushSpecs.keySet();
        for (int pushAttempt = 0; pushAttempt < MAX_PUSH_ATTEMPTS && !remainingRoots.isEmpty(); pushAttempt++, remainingRoots = getRejectedAndNotPushed(results)) {
            Map<GitRepository, GitPushRepoResult> resultMap = push(remainingRoots);
            results.putAll(resultMap);
            GroupedPushResult result = GroupedPushResult.group(resultMap);
            // stop if error happens, or if push is rejected for a custom reason (not because a pull is needed)
            if (!result.errors.isEmpty() || !result.customRejected.isEmpty()) {
                break;
            }
            // propose to update if rejected
            if (!result.rejected.isEmpty()) {
                boolean shouldUpdate = true;
                if (myForce || pushingToNotTrackedBranch(result.rejected)) {
                    shouldUpdate = false;
                } else if (pushAttempt == 0 && !mySettings.autoUpdateIfPushRejected()) {
                    // the dialog will be shown => check for rebase-over-merge problem in advance to avoid showing several dialogs in a row
                    rebaseOverMergeProblemDetected = !findRootsWithMergeCommits(getRootsToUpdate(updateSettings, result.rejected.keySet())).isEmpty();
                    updateSettings = showDialogAndGetExitCode(result.rejected.keySet(), updateSettings, rebaseOverMergeProblemDetected.booleanValue());
                    if (updateSettings != null) {
                        savePushUpdateSettings(updateSettings, rebaseOverMergeProblemDetected.booleanValue());
                    } else {
                        shouldUpdate = false;
                    }
                }
                if (!shouldUpdate) {
                    break;
                }
                if (beforePushLabel == null) {
                    // put the label only before the very first update
                    beforePushLabel = LocalHistory.getInstance().putSystemLabel(myProject, "Before push");
                }
                Collection<GitRepository> rootsToUpdate = getRootsToUpdate(updateSettings, result.rejected.keySet());
                GitUpdateResult updateResult = update(rootsToUpdate, updateSettings.getUpdateMethod(), rebaseOverMergeProblemDetected == null);
                for (GitRepository repository : rootsToUpdate) {
                    // TODO update result in GitUpdateProcess is a single for several roots
                    updatedRoots.put(repository, updateResult);
                }
                if (!updateResult.isSuccess() || updateResult == GitUpdateResult.SUCCESS_WITH_RESOLVED_CONFLICTS || updateResult == GitUpdateResult.INCOMPLETE) {
                    break;
                }
            }
        }
    } finally {
        if (beforePushLabel != null) {
            afterPushLabel = LocalHistory.getInstance().putSystemLabel(myProject, "After push");
        }
        for (GitRepository repository : myPushSpecs.keySet()) {
            repository.update();
        }
    }
    return prepareCombinedResult(results, updatedRoots, preUpdatePositions, beforePushLabel, afterPushLabel);
}
Also used : Label(com.intellij.history.Label) GitRepository(git4idea.repo.GitRepository) GitUpdateResult(git4idea.update.GitUpdateResult) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with GitUpdateResult

use of git4idea.update.GitUpdateResult in project intellij-community by JetBrains.

the class GitPushOperation method update.

@NotNull
protected GitUpdateResult update(@NotNull Collection<GitRepository> rootsToUpdate, @NotNull UpdateMethod updateMethod, boolean checkForRebaseOverMergeProblem) {
    GitUpdateResult updateResult = new GitUpdateProcess(myProject, myProgressIndicator, new HashSet<>(rootsToUpdate), UpdatedFiles.create(), checkForRebaseOverMergeProblem).update(updateMethod);
    for (GitRepository repository : rootsToUpdate) {
        repository.getRoot().refresh(true, true);
        repository.update();
    }
    return updateResult;
}
Also used : GitUpdateProcess(git4idea.update.GitUpdateProcess) GitUpdateResult(git4idea.update.GitUpdateResult) GitRepository(git4idea.repo.GitRepository) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with GitUpdateResult

use of git4idea.update.GitUpdateResult in project intellij-community by JetBrains.

the class GithubRebaseAction method doRebaseCurrentBranch.

private static void doRebaseCurrentBranch(@NotNull final Project project, @NotNull final VirtualFile root, @NotNull final ProgressIndicator indicator) {
    final GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(project);
    Git git = ServiceManager.getService(Git.class);
    final GitRebaser rebaser = new GitRebaser(project, git, indicator);
    final GitLineHandler handler = new GitLineHandler(project, root, GitCommand.REBASE);
    handler.setStdoutSuppressed(false);
    handler.addParameters("upstream/master");
    final GitRebaseProblemDetector rebaseConflictDetector = new GitRebaseProblemDetector();
    handler.addLineListener(rebaseConflictDetector);
    final GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector = new GitUntrackedFilesOverwrittenByOperationDetector(root);
    final GitLocalChangesWouldBeOverwrittenDetector localChangesDetector = new GitLocalChangesWouldBeOverwrittenDetector(root, CHECKOUT);
    handler.addLineListener(untrackedFilesDetector);
    handler.addLineListener(localChangesDetector);
    handler.addLineListener(GitStandardProgressAnalyzer.createListener(indicator));
    String oldText = indicator.getText();
    indicator.setText("Rebasing from upstream/master...");
    GitCommandResult rebaseResult = git.runCommand(handler);
    indicator.setText(oldText);
    repositoryManager.updateRepository(root);
    if (rebaseResult.success()) {
        root.refresh(false, true);
        GithubNotifications.showInfo(project, "Success", "Successfully rebased GitHub fork");
    } else {
        GitUpdateResult result = rebaser.handleRebaseFailure(handler, root, rebaseConflictDetector, untrackedFilesDetector, localChangesDetector);
        if (result == GitUpdateResult.NOTHING_TO_UPDATE || result == GitUpdateResult.SUCCESS || result == GitUpdateResult.SUCCESS_WITH_RESOLVED_CONFLICTS) {
            GithubNotifications.showInfo(project, "Success", "Successfully rebased GitHub fork");
        }
    }
}
Also used : GitUpdateResult(git4idea.update.GitUpdateResult) GitRepositoryManager(git4idea.repo.GitRepositoryManager) GitRebaseProblemDetector(git4idea.rebase.GitRebaseProblemDetector) GitRebaser(git4idea.rebase.GitRebaser)

Aggregations

GitUpdateResult (git4idea.update.GitUpdateResult)4 GitRepository (git4idea.repo.GitRepository)3 NotNull (org.jetbrains.annotations.NotNull)2 Label (com.intellij.history.Label)1 UpdatedFiles (com.intellij.openapi.vcs.update.UpdatedFiles)1 GitRebaseProblemDetector (git4idea.rebase.GitRebaseProblemDetector)1 GitRebaser (git4idea.rebase.GitRebaser)1 GitRepositoryManager (git4idea.repo.GitRepositoryManager)1 GitUpdateProcess (git4idea.update.GitUpdateProcess)1