Search in sources :

Example 36 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 37 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)

Example 38 with HgCommandResult

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

the class HgIntegrationEnabler method initOrNotifyError.

@Override
protected boolean initOrNotifyError(@NotNull final VirtualFile projectDir) {
    final boolean[] success = new boolean[1];
    new HgInitCommand(myProject).executeAsynchronously(projectDir, new HgCommandResultHandler() {

        @Override
        public void process(@Nullable HgCommandResult result) {
            VcsNotifier notifier = VcsNotifier.getInstance(myProject);
            if (!HgErrorUtil.hasErrorsInCommandExecution(result)) {
                success[0] = true;
                refreshVcsDir(projectDir, HgUtil.DOT_HG);
                notifier.notifySuccess(message("hg4idea.init.created.notification.title"), message("hg4idea.init.created.notification.description", projectDir.getPresentableUrl()));
            } else {
                success[0] = false;
                String errors = result != null ? result.getRawError() : "";
                notifier.notifyError(message("hg4idea.init.error.description", projectDir.getPresentableUrl()), errors);
            }
        }
    });
    return success[0];
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgCommandResultHandler(org.zmlx.hg4idea.execution.HgCommandResultHandler) HgInitCommand(org.zmlx.hg4idea.command.HgInitCommand) VcsNotifier(com.intellij.openapi.vcs.VcsNotifier)

Example 39 with HgCommandResult

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

the class HgCloneDialog method test.

@NotNull
@Override
protected TestResult test(@NotNull final String url) {
    HgIdentifyCommand identifyCommand = new HgIdentifyCommand(myProject);
    identifyCommand.setSource(url);
    HgCommandResult result = identifyCommand.execute(ModalityState.stateForComponent(getRootPane()));
    return result != null && result.getExitValue() == 0 ? TestResult.SUCCESS : new TestResult(result.getRawError());
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgIdentifyCommand(org.zmlx.hg4idea.command.HgIdentifyCommand) NotNull(org.jetbrains.annotations.NotNull)

Example 40 with HgCommandResult

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

the class HgQNewCommand method executeQNewInCurrentThread.

private void executeQNewInCurrentThread(@NotNull List<String> chunkFiles) throws VcsException {
    List<String> args = ContainerUtil.newArrayList();
    args.add("-l");
    args.add(saveCommitMessage().getAbsolutePath());
    args.add("-UD");
    String patchName = DATE_FORMAT.format(new Date()).concat(".diff");
    args.add(patchName);
    args.addAll(chunkFiles);
    HgCommandExecutor executor = new HgCommandExecutor(myProject);
    HgCommandResult result = executor.executeInCurrentThread(myRepository.getRoot(), "qnew", args);
    if (HgErrorUtil.hasErrorsInCommandExecution(result)) {
        new HgCommandResultNotifier(myProject).notifyError(result, "Qnew Failed", "Could not create mq patch for selected changes");
    }
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgCommandExecutor(org.zmlx.hg4idea.execution.HgCommandExecutor) HgCommandResultNotifier(org.zmlx.hg4idea.action.HgCommandResultNotifier) Date(java.util.Date)

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