Search in sources :

Example 21 with HgCommandResult

use of org.zmlx.hg4idea.execution.HgCommandResult 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)

Example 22 with HgCommandResult

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

the class HgChangesetsCommand method getRevisions.

protected List<HgRevisionNumber> getRevisions(VirtualFile repo) {
    List<String> args = new ArrayList<>(Arrays.asList("--template", HgChangesetUtil.makeTemplate("{rev}", "{node}", "{author}", "{desc|firstline}"), "--quiet"));
    addArguments(args);
    HgCommandResult result = executeCommandInCurrentThread(repo, args);
    if (result == null) {
        return Collections.emptyList();
    }
    String output = result.getRawOutput();
    if (StringUtil.isEmpty(output)) {
        return Collections.emptyList();
    }
    String[] changesets = output.split(HgChangesetUtil.CHANGESET_SEPARATOR);
    List<HgRevisionNumber> revisions = new ArrayList<>(changesets.length);
    for (String changeset : changesets) {
        List<String> parts = StringUtil.split(changeset, HgChangesetUtil.ITEM_SEPARATOR);
        if (parts.size() >= 3) {
            //support zero commit message
            revisions.add(HgRevisionNumber.getInstance(parts.get(0), parts.get(1), parts.get(2), parts.size() > 3 ? parts.get(3) : ""));
        } else {
            LOG.warn("Could not parse changeset [" + changeset + "]");
        }
    }
    return revisions;
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) ArrayList(java.util.ArrayList)

Example 23 with HgCommandResult

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

the class HgPullCommand method executeInCurrentThread.

public HgCommandExitCode executeInCurrentThread() {
    List<String> arguments = new LinkedList<>();
    if (update) {
        arguments.add("--update");
    } else if (rebase) {
        arguments.add("--rebase");
    }
    if (!StringUtil.isEmptyOrSpaces(revision)) {
        arguments.add("--rev");
        arguments.add(revision);
    }
    arguments.add(source);
    final HgRemoteCommandExecutor executor = new HgRemoteCommandExecutor(project, source);
    executor.setShowOutput(true);
    HgCommandResult result = executor.executeInCurrentThread(repo, "pull", arguments);
    if (HgErrorUtil.isAuthorizationError(result)) {
        new HgCommandResultNotifier(project).notifyError(result, "Authorization required", "http authorization required for <code>" + source + "</code>");
        return ERROR;
    } else if (HgErrorUtil.isAbort(result) || result.getExitValue() > 1) {
        //if result == null - > isAbort returns true
        new HgCommandResultNotifier(project).notifyError(result, "", "Pull failed");
        return ERROR;
    } else if (result.getExitValue() == 1) {
        return UNRESOLVED;
    } else {
        project.getMessageBus().syncPublisher(HgVcs.REMOTE_TOPIC).update(project, null);
        return SUCCESS;
    }
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgRemoteCommandExecutor(org.zmlx.hg4idea.execution.HgRemoteCommandExecutor) HgCommandResultNotifier(org.zmlx.hg4idea.action.HgCommandResultNotifier) LinkedList(java.util.LinkedList)

Example 24 with HgCommandResult

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

the class HgRemoteChangesetsCommand method executeCommandInCurrentThread.

@Override
protected HgCommandResult executeCommandInCurrentThread(VirtualFile repo, List<String> args) {
    String repositoryURL = getRepositoryUrl(repo);
    if (repositoryURL == null) {
        LOG.info("executeCommand no default path configured");
        return null;
    }
    HgRemoteCommandExecutor executor = new HgRemoteCommandExecutor(project, repositoryURL);
    HgCommandResult result = executor.executeInCurrentThread(repo, command, args);
    if (result == HgCommandResult.CANCELLED || HgErrorUtil.isAuthorizationError(result)) {
        final HgVcs vcs = HgVcs.getInstance(project);
        if (vcs == null) {
            return result;
        }
        new HgCommandResultNotifier(project).notifyError(result, "Checking for incoming/outgoing changes disabled", "Authentication is required to check incoming/outgoing changes in " + repositoryURL + "<br/>You may enable checking for changes <a href='#'>in the Settings</a>.", new NotificationListener() {

            @Override
            public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
                ShowSettingsUtil.getInstance().showSettingsDialog(project, vcs.getConfigurable().getDisplayName());
            }
        });
        final HgProjectSettings projectSettings = vcs.getProjectSettings();
        projectSettings.setCheckIncomingOutgoing(false);
        project.getMessageBus().syncPublisher(HgVcs.INCOMING_OUTGOING_CHECK_TOPIC).hide();
    }
    return result;
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgVcs(org.zmlx.hg4idea.HgVcs) HyperlinkEvent(javax.swing.event.HyperlinkEvent) HgProjectSettings(org.zmlx.hg4idea.HgProjectSettings) HgRemoteCommandExecutor(org.zmlx.hg4idea.execution.HgRemoteCommandExecutor) HgCommandResultNotifier(org.zmlx.hg4idea.action.HgCommandResultNotifier) Notification(com.intellij.notification.Notification) NotificationListener(com.intellij.notification.NotificationListener)

Example 25 with HgCommandResult

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

the class HgResolveCommand method getListAsynchronously.

public void getListAsynchronously(final VirtualFile repo, final Consumer<Map<HgFile, HgResolveStatusEnum>> resultHandler) {
    if (repo == null) {
        resultHandler.consume(Collections.emptyMap());
    }
    final HgCommandExecutor executor = new HgCommandExecutor(myProject);
    executor.setSilent(true);
    executor.execute(repo, "resolve", Collections.singletonList("--list"), new HgCommandResultHandler() {

        @Override
        public void process(@Nullable HgCommandResult result) {
            if (result == null) {
                resultHandler.consume(Collections.emptyMap());
            }
            final Map<HgFile, HgResolveStatusEnum> resolveStatus = handleResult(repo, result);
            resultHandler.consume(resolveStatus);
        }
    });
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgCommandExecutor(org.zmlx.hg4idea.execution.HgCommandExecutor) HgCommandResultHandler(org.zmlx.hg4idea.execution.HgCommandResultHandler)

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