Search in sources :

Example 1 with HgCommandResultNotifier

use of org.zmlx.hg4idea.action.HgCommandResultNotifier 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 2 with HgCommandResultNotifier

use of org.zmlx.hg4idea.action.HgCommandResultNotifier in project intellij-community by JetBrains.

the class HgMergeProvider method loadRevisions.

@NotNull
@Override
public MergeData loadRevisions(@NotNull final VirtualFile file) throws VcsException {
    final MergeData mergeData = new MergeData();
    final VcsRunnable runnable = new VcsRunnable() {

        @Override
        public void run() throws VcsException {
            final HgWorkingCopyRevisionsCommand command = new HgWorkingCopyRevisionsCommand(myProject);
            final VirtualFile repo = HgUtil.getHgRootOrThrow(myProject, file);
            final HgFile hgFile = new HgFile(myProject, file);
            HgRevisionNumber serverRevisionNumber;
            HgRevisionNumber localRevisionNumber;
            HgRevisionNumber baseRevisionNumber = null;
            // there are two possibilities: we have checked in local changes in the selected file or we didn't.
            if (wasFileCheckedIn(repo, file)) {
                // 1. We checked in.
                // We have a merge in progress, which means we have 2 heads (parents).
                // the second one is "their" revision pulled from the parent repo,
                // first parent is the local change.
                // to retrieve the base version we get the parent of the local change, i.e. the [only] parent of the first parent.
                //Which one is local revision depends on which one is merged with,
                // i.e if you update to 17 revision and then merge it with 23, so 17 is your local and 17->parent is your base revision.
                // This may produce misunderstanding when you update your project with merging (your update firstly to next revisions  and then
                // merge with previous). see http://hgbook.red-bean.com/read/managing-releases-and-branchy-development.html
                final Couple<HgRevisionNumber> parents = command.parents(repo, file);
                serverRevisionNumber = parents.second;
                localRevisionNumber = parents.first;
                final HgContentRevision local = HgContentRevision.create(myProject, hgFile, localRevisionNumber);
                mergeData.CURRENT = local.getContentAsBytes();
                // we are sure that we have a common ancestor, because otherwise we'll get "repository is unrelated" error while pulling,
                // due to different root changesets which is prohibited.
                // Find common ancestor of two revisions : hg debugancestor rev1 rev2
                // Using quotes may produce wrong escaping errors on Unix-type systems
                List<String> arguments = new ArrayList<>();
                String localChangeset = localRevisionNumber.getChangeset();
                String serverChangeset = serverRevisionNumber.getChangeset();
                arguments.add(StringUtil.isEmptyOrSpaces(localChangeset) ? localRevisionNumber.getRevision() : localChangeset);
                arguments.add(StringUtil.isEmptyOrSpaces(serverChangeset) ? serverRevisionNumber.getRevision() : serverChangeset);
                HgCommandResult result = new HgPromptCommandExecutor(myProject).executeInCurrentThread(repo, "debugancestor", arguments);
                if (result != null) {
                    String output = result.getRawOutput();
                    final List<String> parts = StringUtil.split(output, ":");
                    if (parts.size() < 2) {
                        LOG.info("Couldn't parse result of debugancestor command execution " + arguments);
                        new HgCommandResultNotifier(myProject).notifyError(null, HgVcsMessages.message("hg4idea.error.debugancestor.command.execution"), HgVcsMessages.message("hg4idea.error.debugancestor.command.description"));
                    } else {
                        baseRevisionNumber = HgRevisionNumber.getInstance(parts.get(0), parts.get(1));
                    }
                } else {
                    LOG.info(HgVcsMessages.message("hg4idea.error.debugancestor.command.execution") + arguments);
                    new HgCommandResultNotifier(myProject).notifyError(null, HgVcsMessages.message("hg4idea.error.debugancestor.command.execution"), HgVcsMessages.message("hg4idea.error.debugancestor.command.description"));
                }
            } else {
                // 2. local changes are not checked in.
                // then there is only one parent, which is server changes.
                // local changes are retrieved from the file system, they are not in the Mercurial yet.
                // base is the only parent of server changes.
                serverRevisionNumber = command.parents(repo, file).first;
                baseRevisionNumber = command.parents(repo, file, serverRevisionNumber).first;
                final File origFile = new File(file.getPath() + ".orig");
                mergeData.CURRENT = VcsUtil.getFileByteContent(origFile);
            }
            if (baseRevisionNumber != null) {
                final HgContentRevision base = HgContentRevision.create(myProject, hgFile, baseRevisionNumber);
                //if file doesn't exist in ancestor revision the base revision should be empty
                mergeData.ORIGINAL = base.getContent() != null ? base.getContentAsBytes() : ArrayUtil.EMPTY_BYTE_ARRAY;
            } else {
                // no base revision means that the file was added simultaneously with different content in both repositories
                mergeData.ORIGINAL = ArrayUtil.EMPTY_BYTE_ARRAY;
            }
            final HgContentRevision server = HgContentRevision.create(myProject, hgFile, serverRevisionNumber);
            mergeData.LAST = server.getContentAsBytes();
            file.refresh(false, false);
        }
    };
    VcsUtil.runVcsProcessWithProgress(runnable, VcsBundle.message("multiple.file.merge.loading.progress.title"), false, myProject);
    return mergeData;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsRunnable(com.intellij.vcsUtil.VcsRunnable) HgContentRevision(org.zmlx.hg4idea.HgContentRevision) HgPromptCommandExecutor(org.zmlx.hg4idea.execution.HgPromptCommandExecutor) MergeData(com.intellij.openapi.vcs.merge.MergeData) ArrayList(java.util.ArrayList) HgCommandResultNotifier(org.zmlx.hg4idea.action.HgCommandResultNotifier) HgWorkingCopyRevisionsCommand(org.zmlx.hg4idea.command.HgWorkingCopyRevisionsCommand) HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgFile(org.zmlx.hg4idea.HgFile) HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgFile(org.zmlx.hg4idea.HgFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with HgCommandResultNotifier

use of org.zmlx.hg4idea.action.HgCommandResultNotifier 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 4 with HgCommandResultNotifier

use of org.zmlx.hg4idea.action.HgCommandResultNotifier in project intellij-community by JetBrains.

the class HgQFinishCommand method execute.

public void execute(@NotNull final String revision) {
    final Project project = myRepository.getProject();
    new HgCommandExecutor(project).execute(myRepository.getRoot(), "qfinish", Collections.singletonList("qbase:" + revision), new HgCommandResultHandler() {

        @Override
        public void process(@Nullable HgCommandResult result) {
            if (HgErrorUtil.hasErrorsInCommandExecution(result)) {
                new HgCommandResultNotifier(project).notifyError(result, "QFinish command failed", "Could not apply patches into repository history.");
            }
            myRepository.update();
        }
    });
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) Project(com.intellij.openapi.project.Project) HgCommandExecutor(org.zmlx.hg4idea.execution.HgCommandExecutor) HgCommandResultHandler(org.zmlx.hg4idea.execution.HgCommandResultHandler) HgCommandResultNotifier(org.zmlx.hg4idea.action.HgCommandResultNotifier)

Example 5 with HgCommandResultNotifier

use of org.zmlx.hg4idea.action.HgCommandResultNotifier 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

HgCommandResultNotifier (org.zmlx.hg4idea.action.HgCommandResultNotifier)20 HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)19 HgCommandExecutor (org.zmlx.hg4idea.execution.HgCommandExecutor)11 Project (com.intellij.openapi.project.Project)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 File (java.io.File)2 HgCommandResultHandler (org.zmlx.hg4idea.execution.HgCommandResultHandler)2 HgRemoteCommandExecutor (org.zmlx.hg4idea.execution.HgRemoteCommandExecutor)2 HgConflictResolver (org.zmlx.hg4idea.provider.update.HgConflictResolver)2 Notification (com.intellij.notification.Notification)1 NotificationListener (com.intellij.notification.NotificationListener)1 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 MergeData (com.intellij.openapi.vcs.merge.MergeData)1 UpdatedFiles (com.intellij.openapi.vcs.update.UpdatedFiles)1 VcsRunnable (com.intellij.vcsUtil.VcsRunnable)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1