Search in sources :

Example 1 with GitConflictResolver

use of git4idea.merge.GitConflictResolver in project intellij-community by JetBrains.

the class GitBranchUiHandlerImpl method showUnmergedFilesNotification.

@Override
public void showUnmergedFilesNotification(@NotNull final String operationName, @NotNull final Collection<GitRepository> repositories) {
    String title = unmergedFilesErrorTitle(operationName);
    String description = unmergedFilesErrorNotificationDescription(operationName);
    VcsNotifier.getInstance(myProject).notifyError(title, description, new NotificationListener() {

        @Override
        public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
            if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED && event.getDescription().equals("resolve")) {
                GitConflictResolver.Params params = new GitConflictResolver.Params().setMergeDescription(String.format("The following files have unresolved conflicts. You need to resolve them before %s.", operationName)).setErrorNotificationTitle("Unresolved files remain.");
                new GitConflictResolver(myProject, myGit, GitUtil.getRootsFromRepositories(repositories), params).merge();
            }
        }
    });
}
Also used : GitConflictResolver(git4idea.merge.GitConflictResolver) HyperlinkEvent(javax.swing.event.HyperlinkEvent) Notification(com.intellij.notification.Notification) NotificationListener(com.intellij.notification.NotificationListener)

Example 2 with GitConflictResolver

use of git4idea.merge.GitConflictResolver in project intellij-community by JetBrains.

the class GitUpdateProcess method checkRebaseInProgress.

/**
   * Check if rebase is in progress, propose to resolve conflicts.
   * @return true if rebase is in progress, which means that update can't continue.
   */
private boolean checkRebaseInProgress() {
    LOG.info("checkRebaseInProgress: checking if there is an unfinished rebase process...");
    final GitRebaser rebaser = new GitRebaser(myProject, myGit, myProgressIndicator);
    final Collection<VirtualFile> rebasingRoots = rebaser.getRebasingRoots();
    if (rebasingRoots.isEmpty()) {
        return false;
    }
    LOG.info("checkRebaseInProgress: roots with unfinished rebase: " + rebasingRoots);
    GitConflictResolver.Params params = new GitConflictResolver.Params();
    params.setErrorNotificationTitle("Can't update");
    params.setMergeDescription("You have unfinished rebase process. These conflicts must be resolved before update.");
    params.setErrorNotificationAdditionalDescription("Then you may <b>continue rebase</b>. <br/> You also may <b>abort rebase</b> to restore the original branch and stop rebasing.");
    params.setReverse(true);
    return !new GitConflictResolver(myProject, myGit, rebasingRoots, params) {

        @Override
        protected boolean proceedIfNothingToMerge() {
            return rebaser.continueRebase(rebasingRoots);
        }

        @Override
        protected boolean proceedAfterAllMerged() {
            return rebaser.continueRebase(rebasingRoots);
        }
    }.merge();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitConflictResolver(git4idea.merge.GitConflictResolver) GitRebaser(git4idea.rebase.GitRebaser)

Example 3 with GitConflictResolver

use of git4idea.merge.GitConflictResolver in project intellij-community by JetBrains.

the class GitRebaser method handleRebaseFailure.

/**
   * @return true if the failure situation was resolved successfully, false if we failed to resolve the problem.
   */
private boolean handleRebaseFailure(final VirtualFile root, final GitLineHandler h, GitRebaseProblemDetector rebaseConflictDetector) {
    if (rebaseConflictDetector.isMergeConflict()) {
        LOG.info("handleRebaseFailure merge conflict");
        return new GitConflictResolver(myProject, myGit, Collections.singleton(root), makeParamsForRebaseConflict()) {

            @Override
            protected boolean proceedIfNothingToMerge() {
                return continueRebase(root, "--continue");
            }

            @Override
            protected boolean proceedAfterAllMerged() {
                return continueRebase(root, "--continue");
            }
        }.merge();
    } else if (rebaseConflictDetector.isNoChangeError()) {
        LOG.info("handleRebaseFailure no changes error detected");
        try {
            if (GitUtil.hasLocalChanges(true, myProject, root)) {
                LOG.error("The rebase detector incorrectly detected 'no changes' situation. Attempting to continue rebase.");
                return continueRebase(root);
            } else if (GitUtil.hasLocalChanges(false, myProject, root)) {
                LOG.warn("No changes from patch were not added to the index. Adding all changes from tracked files.");
                stageEverything(root);
                return continueRebase(root);
            } else {
                GitRebaseUtils.CommitInfo commit = GitRebaseUtils.getCurrentRebaseCommit(myProject, root);
                LOG.info("no changes confirmed. Skipping commit " + commit);
                mySkippedCommits.add(commit);
                return continueRebase(root, "--skip");
            }
        } catch (VcsException e) {
            LOG.info("Failed to work around 'no changes' error.", e);
            String message = "Couldn't proceed with rebase. " + e.getMessage();
            GitUIUtil.notifyImportantError(myProject, "Error rebasing", message);
            return false;
        }
    } else {
        LOG.info("handleRebaseFailure error " + h.errors());
        GitUIUtil.notifyImportantError(myProject, "Error rebasing", GitUIUtil.stringifyErrors(h.errors()));
        return false;
    }
}
Also used : GitConflictResolver(git4idea.merge.GitConflictResolver) VcsException(com.intellij.openapi.vcs.VcsException)

Example 4 with GitConflictResolver

use of git4idea.merge.GitConflictResolver in project intellij-community by JetBrains.

the class GitPreservingProcess method configureSaver.

/**
   * Configures the saver: i.e. notifications and texts for the GitConflictResolver used inside.
   */
@NotNull
private GitChangesSaver configureSaver(@NotNull GitVcsSettings.UpdateChangesPolicy saveMethod) {
    GitChangesSaver saver = GitChangesSaver.getSaver(myProject, myGit, myProgressIndicator, myStashMessage, saveMethod);
    MergeDialogCustomizer mergeDialogCustomizer = new MergeDialogCustomizer() {

        @Override
        public String getMultipleFileMergeDescription(@NotNull Collection<VirtualFile> files) {
            return String.format("<html>Uncommitted changes that were saved before %s have conflicts with files from <code>%s</code></html>", myOperationTitle, myDestinationName);
        }

        @Override
        public String getLeftPanelTitle(@NotNull VirtualFile file) {
            return "Uncommitted changes from stash";
        }

        @Override
        public String getRightPanelTitle(@NotNull VirtualFile file, VcsRevisionNumber revisionNumber) {
            return String.format("<html>Changes from <b><code>%s</code></b></html>", myDestinationName);
        }
    };
    GitConflictResolver.Params params = new GitConflictResolver.Params().setReverse(true).setMergeDialogCustomizer(mergeDialogCustomizer).setErrorNotificationTitle("Local changes were not restored");
    saver.setConflictResolverParams(params);
    return saver;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MergeDialogCustomizer(com.intellij.openapi.vcs.merge.MergeDialogCustomizer) GitConflictResolver(git4idea.merge.GitConflictResolver) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) Collection(java.util.Collection) GitChangesSaver(git4idea.stash.GitChangesSaver) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GitConflictResolver (git4idea.merge.GitConflictResolver)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Notification (com.intellij.notification.Notification)1 NotificationListener (com.intellij.notification.NotificationListener)1 VcsException (com.intellij.openapi.vcs.VcsException)1 VcsRevisionNumber (com.intellij.openapi.vcs.history.VcsRevisionNumber)1 MergeDialogCustomizer (com.intellij.openapi.vcs.merge.MergeDialogCustomizer)1 GitRebaser (git4idea.rebase.GitRebaser)1 GitChangesSaver (git4idea.stash.GitChangesSaver)1 Collection (java.util.Collection)1 HyperlinkEvent (javax.swing.event.HyperlinkEvent)1 NotNull (org.jetbrains.annotations.NotNull)1