Search in sources :

Example 1 with HgConflictResolver

use of org.zmlx.hg4idea.provider.update.HgConflictResolver in project intellij-community by JetBrains.

the class HgUpdateCommand method updateRepoToInCurrentThread.

public static boolean updateRepoToInCurrentThread(@NotNull final Project project, @NotNull final VirtualFile repository, @NotNull final String targetRevision, final boolean clean) {
    final HgUpdateCommand hgUpdateCommand = new HgUpdateCommand(project, repository);
    hgUpdateCommand.setRevision(targetRevision);
    hgUpdateCommand.setClean(clean);
    HgCommandResult result = hgUpdateCommand.execute();
    new HgConflictResolver(project).resolve(repository);
    boolean success = !HgErrorUtil.isCommandExecutionFailed(result);
    boolean hasUnresolvedConflicts = HgConflictResolver.hasConflicts(project, repository);
    if (!success) {
        new HgCommandResultNotifier(project).notifyError(result, "", "Update failed");
    } else if (hasUnresolvedConflicts) {
        new VcsNotifier(project).notifyImportantWarning("Unresolved conflicts.", HgVcsMessages.message("hg4idea.update.warning.merge.conflicts", repository.getPath()));
    }
    getRepositoryManager(project).updateRepository(repository);
    HgErrorUtil.markDirtyAndHandleErrors(project, repository);
    return success;
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgCommandResultNotifier(org.zmlx.hg4idea.action.HgCommandResultNotifier) HgConflictResolver(org.zmlx.hg4idea.provider.update.HgConflictResolver) VcsNotifier(com.intellij.openapi.vcs.VcsNotifier)

Example 2 with HgConflictResolver

use of org.zmlx.hg4idea.provider.update.HgConflictResolver in project intellij-community by JetBrains.

the class HgMergeCommand method mergeWith.

public static void mergeWith(@NotNull final HgRepository repository, @NotNull final String branchName, @NotNull final UpdatedFiles updatedFiles, @Nullable final Runnable onSuccessHandler) {
    final Project project = repository.getProject();
    final VirtualFile repositoryRoot = repository.getRoot();
    final HgMergeCommand hgMergeCommand = new HgMergeCommand(project, repository);
    //there is no difference between branch or revision or bookmark as parameter to merge,
    hgMergeCommand.setRevision(branchName);
    // we need just a string
    new Task.Backgroundable(project, "Merging Changes...") {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            try {
                HgCommandResult result = hgMergeCommand.mergeSynchronously();
                if (HgErrorUtil.isAncestorMergeError(result)) {
                    //skip and notify
                    VcsNotifier.getInstance(project).notifyMinorWarning("Merging is skipped for " + repositoryRoot.getPresentableName(), "Merging with a working directory ancestor has no effect");
                    return;
                }
                new HgConflictResolver(project, updatedFiles).resolve(repositoryRoot);
                if (!HgConflictResolver.hasConflicts(project, repositoryRoot) && onSuccessHandler != null) {
                    // for example commit changes
                    onSuccessHandler.run();
                }
            } catch (VcsException exception) {
                if (exception.isWarning()) {
                    VcsNotifier.getInstance(project).notifyWarning("Warning during merge", exception.getMessage());
                } else {
                    VcsNotifier.getInstance(project).notifyError("Exception during merge", exception.getMessage());
                }
            }
        }
    }.queue();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) Project(com.intellij.openapi.project.Project) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) HgConflictResolver(org.zmlx.hg4idea.provider.update.HgConflictResolver)

Example 3 with HgConflictResolver

use of org.zmlx.hg4idea.provider.update.HgConflictResolver in project intellij-community by JetBrains.

the class HgCherryPicker method processGrafting.

private static void processGrafting(@NotNull HgRepository repository, @NotNull List<String> hashes) {
    Project project = repository.getProject();
    VirtualFile root = repository.getRoot();
    HgGraftCommand command = new HgGraftCommand(project, repository);
    HgCommandResult result = command.startGrafting(hashes);
    boolean hasConflicts = HgConflictResolver.hasConflicts(project, root);
    if (!hasConflicts && HgErrorUtil.isCommandExecutionFailed(result)) {
        new HgCommandResultNotifier(project).notifyError(result, "Hg Error", "Couldn't  graft.");
        return;
    }
    final UpdatedFiles updatedFiles = UpdatedFiles.create();
    while (hasConflicts) {
        new HgConflictResolver(project, updatedFiles).resolve(root);
        hasConflicts = HgConflictResolver.hasConflicts(project, root);
        if (!hasConflicts) {
            result = command.continueGrafting();
            hasConflicts = HgConflictResolver.hasConflicts(project, root);
        } else {
            new HgCommandResultNotifier(project).notifyError(result, "Hg Error", "Couldn't continue grafting");
            break;
        }
    }
    repository.update();
    root.refresh(true, true);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) Project(com.intellij.openapi.project.Project) HgGraftCommand(org.zmlx.hg4idea.command.HgGraftCommand) UpdatedFiles(com.intellij.openapi.vcs.update.UpdatedFiles) HgCommandResultNotifier(org.zmlx.hg4idea.action.HgCommandResultNotifier) HgConflictResolver(org.zmlx.hg4idea.provider.update.HgConflictResolver)

Aggregations

HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)3 HgConflictResolver (org.zmlx.hg4idea.provider.update.HgConflictResolver)3 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 HgCommandResultNotifier (org.zmlx.hg4idea.action.HgCommandResultNotifier)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 VcsException (com.intellij.openapi.vcs.VcsException)1 VcsNotifier (com.intellij.openapi.vcs.VcsNotifier)1 UpdatedFiles (com.intellij.openapi.vcs.update.UpdatedFiles)1 HgGraftCommand (org.zmlx.hg4idea.command.HgGraftCommand)1