Search in sources :

Example 41 with HgCommandResult

use of org.zmlx.hg4idea.execution.HgCommandResult in project intellij-community by JetBrains.

the class HgResolveCommand method getListSynchronously.

public Map<HgFile, HgResolveStatusEnum> getListSynchronously(VirtualFile repo) {
    if (repo == null) {
        return Collections.emptyMap();
    }
    final HgCommandExecutor executor = new HgCommandExecutor(myProject);
    executor.setSilent(true);
    final HgCommandResult result = executor.executeInCurrentThread(repo, "resolve", Collections.singletonList("--list"));
    if (result == null) {
        return Collections.emptyMap();
    }
    return handleResult(repo, result);
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgCommandExecutor(org.zmlx.hg4idea.execution.HgCommandExecutor)

Example 42 with HgCommandResult

use of org.zmlx.hg4idea.execution.HgCommandResult in project intellij-community by JetBrains.

the class HgRollbackEnvironment method revert.

private void revert(@NotNull List<FilePath> filePaths) {
    for (Map.Entry<VirtualFile, Collection<FilePath>> entry : HgUtil.groupFilePathsByHgRoots(project, filePaths).entrySet()) {
        final VirtualFile repo = entry.getKey();
        final Collection<FilePath> files = entry.getValue();
        HgRevisionNumber revisionNumber = new HgWorkingCopyRevisionsCommand(project).firstParent(repo);
        for (List<String> chunk : VcsFileUtil.chunkPaths(repo, files)) {
            HgCommandResult revertResult = new HgRevertCommand(project).execute(repo, chunk, revisionNumber, false);
            if (HgErrorUtil.hasUncommittedChangesConflict(revertResult)) {
                String message = String.format("<html>Revert failed due to uncommitted merge.<br>" + "Would you like to discard all changes for repository <it><b>%s</b></it>?</html>", repo.getPresentableName());
                int exitCode = HgUpdateCommand.showDiscardChangesConfirmation(project, message);
                if (exitCode == Messages.OK) {
                    //discard all changes for this repository//
                    HgUpdateCommand updateCommand = new HgUpdateCommand(project, repo);
                    updateCommand.setClean(true);
                    updateCommand.setRevision(".");
                    updateCommand.execute();
                }
                break;
            }
            new HgResolveCommand(project).markResolved(repo, files);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FilePath(com.intellij.openapi.vcs.FilePath) HgResolveCommand(org.zmlx.hg4idea.command.HgResolveCommand) HgWorkingCopyRevisionsCommand(org.zmlx.hg4idea.command.HgWorkingCopyRevisionsCommand) HgRevertCommand(org.zmlx.hg4idea.command.HgRevertCommand) HgUpdateCommand(org.zmlx.hg4idea.command.HgUpdateCommand) HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber)

Example 43 with HgCommandResult

use of org.zmlx.hg4idea.execution.HgCommandResult in project intellij-community by JetBrains.

the class HgRegularUpdater method processRebase.

private void processRebase(ProgressIndicator indicator, final UpdatedFiles updatedFiles) throws VcsException {
    indicator.setText2(HgVcsMessages.message("hg4idea.progress.rebase"));
    HgRepository repository = HgUtil.getRepositoryManager(project).getRepositoryForRoot(repoRoot);
    if (repository == null) {
        throw new VcsException("Repository not found for root " + repoRoot);
    }
    HgRebaseCommand rebaseCommand = new HgRebaseCommand(project, repository);
    HgCommandResult result = new HgRebaseCommand(project, repository).startRebase();
    if (HgErrorUtil.isCommandExecutionFailed(result)) {
        new HgCommandResultNotifier(project).notifyError(result, "Hg Error", "Couldn't rebase repository.");
        return;
    }
    //noinspection ConstantConditions
    while (result.getExitValue() == 1) {
        //if result == null isAbort will be true;
        resolvePossibleConflicts(updatedFiles);
        if (HgConflictResolver.hasConflicts(project, repoRoot) || HgErrorUtil.isNothingToRebase(result)) {
            break;
        }
        result = rebaseCommand.continueRebase();
        if (HgErrorUtil.isAbort(result)) {
            new HgCommandResultNotifier(project).notifyError(result, "Hg Error", "Couldn't continue rebasing");
            break;
        }
    }
    repository.update();
    repoRoot.refresh(true, true);
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) VcsException(com.intellij.openapi.vcs.VcsException) HgRepository(org.zmlx.hg4idea.repo.HgRepository) HgCommandResultNotifier(org.zmlx.hg4idea.action.HgCommandResultNotifier)

Example 44 with HgCommandResult

use of org.zmlx.hg4idea.execution.HgCommandResult in project intellij-community by JetBrains.

the class HgCheckoutProvider method doCheckout.

public void doCheckout(@NotNull final Project project, @Nullable final Listener listener) {
    FileDocumentManager.getInstance().saveAllDocuments();
    final HgCloneDialog dialog = new HgCloneDialog(project);
    if (!dialog.showAndGet()) {
        return;
    }
    dialog.rememberSettings();
    VirtualFile destinationParent = LocalFileSystem.getInstance().findFileByIoFile(new File(dialog.getParentDirectory()));
    if (destinationParent == null) {
        return;
    }
    final String targetDir = destinationParent.getPath() + File.separator + dialog.getDirectoryName();
    final String sourceRepositoryURL = dialog.getSourceRepositoryURL();
    final AtomicReference<HgCommandResult> cloneResult = new AtomicReference<>();
    new Task.Backgroundable(project, HgVcsMessages.message("hg4idea.clone.progress", sourceRepositoryURL), true) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            HgCloneCommand clone = new HgCloneCommand(project);
            clone.setRepositoryURL(sourceRepositoryURL);
            clone.setDirectory(targetDir);
            cloneResult.set(clone.executeInCurrentThread());
        }

        @Override
        public void onSuccess() {
            if (cloneResult.get() == null || HgErrorUtil.hasErrorsInCommandExecution(cloneResult.get())) {
                new HgCommandResultNotifier(project).notifyError(cloneResult.get(), "Clone failed", "Clone from " + sourceRepositoryURL + " failed.");
            } else {
                DvcsUtil.addMappingIfSubRoot(project, targetDir, HgVcs.VCS_NAME);
                if (listener != null) {
                    listener.directoryCheckedOut(new File(dialog.getParentDirectory(), dialog.getDirectoryName()), HgVcs.getKey());
                    listener.checkoutCompleted();
                }
            }
        }
    }.queue();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) AtomicReference(java.util.concurrent.atomic.AtomicReference) HgCloneCommand(org.zmlx.hg4idea.command.HgCloneCommand) HgCommandResultNotifier(org.zmlx.hg4idea.action.HgCommandResultNotifier) HgCloneDialog(org.zmlx.hg4idea.ui.HgCloneDialog) HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 45 with HgCommandResult

use of org.zmlx.hg4idea.execution.HgCommandResult in project intellij-community by JetBrains.

the class HgHistoryProvider method getHistoryForUncommittedRenamed.

/**
   * Workaround for getting follow file history in case of uncommitted move/rename change
   */
private static List<HgFileRevision> getHistoryForUncommittedRenamed(@NotNull FilePath originalHgFilePath, @NotNull VirtualFile vcsRoot, @NotNull Project project, int limit) {
    HgFile originalHgFile = new HgFile(vcsRoot, originalHgFilePath);
    final HgLogCommand logCommand = new HgLogCommand(project);
    logCommand.setIncludeRemoved(true);
    final HgVersion version = logCommand.getVersion();
    String[] templates = HgBaseLogParser.constructFullTemplateArgument(false, version);
    String template = HgChangesetUtil.makeTemplate(templates);
    List<String> argsForCmd = ContainerUtil.newArrayList();
    String relativePath = originalHgFile.getRelativePath();
    argsForCmd.add("--rev");
    argsForCmd.add(String.format("reverse(follow(%s))", relativePath != null ? "'" + FileUtil.toSystemIndependentName(relativePath) + "'" : ""));
    HgCommandResult result = logCommand.execute(vcsRoot, template, limit, relativePath != null ? null : originalHgFile, argsForCmd);
    return HgHistoryUtil.getCommitRecords(project, result, new HgFileRevisionLogParser(project, originalHgFile, version));
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgFile(org.zmlx.hg4idea.HgFile) HgFileRevisionLogParser(org.zmlx.hg4idea.log.HgFileRevisionLogParser) HgVersion(org.zmlx.hg4idea.util.HgVersion) HgLogCommand(org.zmlx.hg4idea.command.HgLogCommand)

Aggregations

HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)54 HgCommandExecutor (org.zmlx.hg4idea.execution.HgCommandExecutor)21 HgCommandResultNotifier (org.zmlx.hg4idea.action.HgCommandResultNotifier)19 Project (com.intellij.openapi.project.Project)12 NotNull (org.jetbrains.annotations.NotNull)11 ArrayList (java.util.ArrayList)7 HgVersion (org.zmlx.hg4idea.util.HgVersion)7 VcsException (com.intellij.openapi.vcs.VcsException)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 File (java.io.File)5 LinkedList (java.util.LinkedList)5 HgCommandResultHandler (org.zmlx.hg4idea.execution.HgCommandResultHandler)5 AccessToken (com.intellij.openapi.application.AccessToken)4 Nullable (org.jetbrains.annotations.Nullable)4 HgRevisionNumber (org.zmlx.hg4idea.HgRevisionNumber)4 HgVcs (org.zmlx.hg4idea.HgVcs)4 HgRevertCommand (org.zmlx.hg4idea.command.HgRevertCommand)4 SmartList (com.intellij.util.SmartList)3 HgFile (org.zmlx.hg4idea.HgFile)3 HgRemoteCommandExecutor (org.zmlx.hg4idea.execution.HgRemoteCommandExecutor)3