Search in sources :

Example 1 with HgCommandResult

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

the class HgRegularUpdater method update.

private void update(@NotNull VirtualFile repo, ProgressIndicator indicator, UpdatedFiles updatedFiles, List<VcsException> warnings) throws VcsException {
    indicator.setText2(HgVcsMessages.message("hg4idea.progress.updatingworkingdir"));
    HgRevisionNumber parentBeforeUpdate = new HgWorkingCopyRevisionsCommand(project).firstParent(repo);
    HgUpdateCommand hgUpdateCommand = new HgUpdateCommand(project, repo);
    HgCommandResult updateResult = hgUpdateCommand.execute();
    String warningMessages = ensureSuccess(updateResult).getRawError();
    handlePossibleWarning(warnings, warningMessages);
    HgRevisionNumber parentAfterUpdate = new HgWorkingCopyRevisionsCommand(project).firstParent(repo);
    addUpdatedFiles(repo, updatedFiles, parentBeforeUpdate, parentAfterUpdate);
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult)

Example 2 with HgCommandResult

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

the class HgRegularUpdater method update.

public boolean update(final UpdatedFiles updatedFiles, ProgressIndicator indicator, List<VcsException> warnings) throws VcsException {
    indicator.setText(HgVcsMessages.message("hg4idea.progress.updating", repoRoot.getPath()));
    String defaultPath = HgUtil.getRepositoryDefaultPath(project, repoRoot);
    if (StringUtil.isEmptyOrSpaces(defaultPath)) {
        throw new VcsException(HgVcsMessages.message("hg4idea.warning.no-default-update-path", repoRoot.getPath()));
    }
    List<HgRevisionNumber> branchHeadsBeforePull = new HgHeadsCommand(project, repoRoot).executeInCurrentThread();
    if (branchHeadsBeforePull.size() > 1) {
        reportWarning(warnings, HgVcsMessages.message("hg4idea.update.warning.multipleHeadsBeforeUpdate", repoRoot.getPath()));
    }
    if (updateConfiguration.shouldPull()) {
        HgCommandExitCode pullResult = pull(repoRoot, indicator);
        if (pullResult == HgCommandExitCode.ERROR) {
            return false;
        }
    }
    List<HgRevisionNumber> parentsBeforeUpdate = new HgWorkingCopyRevisionsCommand(project).parents(repoRoot);
    if (parentsBeforeUpdate.size() > 1) {
        throw new VcsException(HgVcsMessages.message("hg4idea.update.error.uncommittedMerge", repoRoot.getPath()));
    }
    indicator.setText2(HgVcsMessages.message("hg4idea.progress.countingHeads"));
    List<HgRevisionNumber> branchHeadsAfterPull = new HgHeadsCommand(project, repoRoot).executeInCurrentThread();
    List<HgRevisionNumber> pulledBranchHeads = determinePulledBranchHeads(branchHeadsBeforePull, branchHeadsAfterPull);
    List<HgRevisionNumber> remainingOriginalBranchHeads = determingRemainingOriginalBranchHeads(branchHeadsBeforePull, branchHeadsAfterPull);
    HgUpdateType updateType = updateConfiguration.getUpdateType();
    if (branchHeadsAfterPull.size() > 1 && updateType != ONLY_UPDATE) {
        // merge strategy
        if (updateType == MERGE) {
            abortOnLocalChanges();
            abortOnMultiplePulledHeads(pulledBranchHeads);
            abortOnMultipleLocalHeads(remainingOriginalBranchHeads);
            HgCommandResult mergeResult = doMerge(indicator);
            if (updateConfiguration.shouldCommitAfterMerge()) {
                commitOrWarnAboutConflicts(warnings, mergeResult);
            }
        } else //rebase strategy
        {
            //resolve conflicts processed during rebase
            processRebase(indicator, updatedFiles);
            return true;
        }
    } else //if pull complete successfully and there are only one head, we need just update working directory to the head
    {
        //in case of multiple heads the update will report the appropriate error
        update(repoRoot, indicator, updatedFiles, warnings);
    }
    //any kind of update could have resulted in merges and merge conflicts, so run the resolver
    resolvePossibleConflicts(updatedFiles);
    return true;
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) VcsException(com.intellij.openapi.vcs.VcsException)

Example 3 with HgCommandResult

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

the class HgOutgoingCommitsProvider method getOutgoingCommits.

@NotNull
@Override
public OutgoingResult getOutgoingCommits(@NotNull final HgRepository repository, @NotNull final PushSpec<HgPushSource, HgTarget> pushSpec, boolean initial) {
    final Project project = repository.getProject();
    HgVcs hgvcs = HgVcs.getInstance(project);
    assert hgvcs != null;
    final HgVersion version = hgvcs.getVersion();
    String[] templates = HgBaseLogParser.constructFullTemplateArgument(true, version);
    HgOutgoingCommand hgOutgoingCommand = new HgOutgoingCommand(project);
    HgTarget hgTarget = pushSpec.getTarget();
    List<VcsError> errors = new ArrayList<>();
    if (StringUtil.isEmptyOrSpaces(hgTarget.myTarget)) {
        errors.add(new VcsError("Hg push path could not be empty."));
        return new OutgoingResult(Collections.<VcsFullCommitDetails>emptyList(), errors);
    }
    HgCommandResult result = hgOutgoingCommand.execute(repository.getRoot(), HgChangesetUtil.makeTemplate(templates), pushSpec.getSource().getPresentation(), hgTarget.myTarget, initial);
    if (result == null) {
        errors.add(new VcsError("Couldn't execute hg outgoing command for " + repository));
        return new OutgoingResult(Collections.<VcsFullCommitDetails>emptyList(), errors);
    }
    List<String> resultErrors = result.getErrorLines();
    if (resultErrors != null && !resultErrors.isEmpty() && result.getExitValue() != 0) {
        for (String error : resultErrors) {
            if (HgErrorUtil.isAbortLine(error)) {
                if (HgErrorUtil.isAuthorizationError(error)) {
                    VcsError authorizationError = new VcsError(error + "<a href='authenticate'>" + LOGIN_AND_REFRESH_LINK + "</a>", new VcsErrorHandler() {

                        public void handleError(@NotNull CommitLoader commitLoader) {
                            commitLoader.reloadCommits();
                        }
                    });
                    errors.add(authorizationError);
                } else {
                    errors.add(new VcsError(error));
                }
            }
        }
        LOG.warn(resultErrors.toString());
    }
    return new OutgoingResult(HgHistoryUtil.createFullCommitsFromResult(project, repository.getRoot(), result, version, true), errors);
}
Also used : HgVcs(org.zmlx.hg4idea.HgVcs) ArrayList(java.util.ArrayList) HgOutgoingCommand(org.zmlx.hg4idea.command.HgOutgoingCommand) HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) Project(com.intellij.openapi.project.Project) HgVersion(org.zmlx.hg4idea.util.HgVersion) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with HgCommandResult

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

the class HgPusher method pushSynchronously.

public static void pushSynchronously(@NotNull final Project project, @NotNull HgPushCommand command) {
    final VirtualFile repo = command.getRepo();
    HgCommandResult result = command.executeInCurrentThread();
    if (result == null) {
        return;
    }
    if (result.getExitValue() == PUSH_SUCCEEDED_EXIT_VALUE) {
        int commitsNum = getNumberOfPushedCommits(result);
        String successTitle = "Pushed successfully";
        String successDescription = String.format("Pushed %d %s [%s]", commitsNum, StringUtil.pluralize("commit", commitsNum), repo.getPresentableName());
        VcsNotifier.getInstance(project).notifySuccess(successTitle, successDescription);
    } else if (result.getExitValue() == NOTHING_TO_PUSH_EXIT_VALUE) {
        VcsNotifier.getInstance(project).notifySuccess("Nothing to push");
    } else {
        new HgCommandResultNotifier(project).notifyError(result, "Push failed", "Failed to push to [" + repo.getPresentableName() + "]");
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgCommandResultNotifier(org.zmlx.hg4idea.action.HgCommandResultNotifier)

Example 5 with HgCommandResult

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

the class HgRepositoryImpl method update.

@Override
public void update() {
    HgRepoInfo currentInfo = readRepoInfo();
    // update only if something changed!!!   if update every time - new log will be refreshed every time, too.
    // Then blinking and do not work properly;
    final Project project = getProject();
    if (!project.isDisposed() && !currentInfo.equals(myInfo)) {
        myInfo = currentInfo;
        HgCommandResult branchCommandResult = new HgBranchesCommand(project, getRoot()).collectBranches();
        if (branchCommandResult == null || branchCommandResult.getExitValue() != 0) {
            // hg executable is not valid
            LOG.warn("Could not collect hg opened branches.");
            myOpenedBranches = myInfo.getBranches().keySet();
        } else {
            myOpenedBranches = HgBranchesCommand.collectNames(branchCommandResult);
        }
        HgUtil.executeOnPooledThread(new Runnable() {

            public void run() {
                if (!project.isDisposed()) {
                    project.getMessageBus().syncPublisher(HgVcs.STATUS_TOPIC).update(project, getRoot());
                }
            }
        }, project);
    }
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) Project(com.intellij.openapi.project.Project) HgBranchesCommand(org.zmlx.hg4idea.command.HgBranchesCommand)

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