Search in sources :

Example 1 with HgCommandException

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

the class HgTagCreateCommand method executeAsynchronously.

public void executeAsynchronously(HgCommandResultHandler resultHandler) throws HgCommandException {
    if (StringUtil.isEmptyOrSpaces(tagName)) {
        throw new HgCommandException("tag name is empty");
    }
    List<String> arguments = new ArrayList<>();
    arguments.add(tagName);
    if (!StringUtil.isEmptyOrSpaces(revisionNumberOrHash)) {
        arguments.add("--rev");
        arguments.add(revisionNumberOrHash);
    }
    new HgCommandExecutor(project).execute(repo, "tag", arguments, resultHandler);
    if (!project.isDisposed()) {
        HgRepositoryManager manager = HgUtil.getRepositoryManager(project);
        manager.updateRepository(repo);
    }
}
Also used : HgCommandExecutor(org.zmlx.hg4idea.execution.HgCommandExecutor) HgRepositoryManager(org.zmlx.hg4idea.repo.HgRepositoryManager) ArrayList(java.util.ArrayList) HgCommandException(org.zmlx.hg4idea.execution.HgCommandException)

Example 2 with HgCommandException

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

the class HgCommitTypeCommand method executeInCurrentThread.

public void executeInCurrentThread() throws HgCommandException, VcsException {
    if (StringUtil.isEmptyOrSpaces(myMessage)) {
        throw new HgCommandException(HgVcsMessages.message("hg4idea.commit.error.messageEmpty"));
    }
    if (myFiles.isEmpty()) {
        executeChunked(Collections.<List<String>>emptyList());
    } else {
        List<String> relativePaths = ContainerUtil.map2List(myFiles, new Function<HgFile, String>() {

            @Override
            public String fun(HgFile file) {
                return file.getRelativePath();
            }
        });
        List<List<String>> chunkedCommits = VcsFileUtil.chunkArguments(relativePaths);
        executeChunked(chunkedCommits);
    }
    myRepository.update();
    final MessageBus messageBus = myProject.getMessageBus();
    messageBus.syncPublisher(HgVcs.REMOTE_TOPIC).update(myProject, null);
}
Also used : HgFile(org.zmlx.hg4idea.HgFile) MessageBus(com.intellij.util.messages.MessageBus) List(java.util.List) HgCommandException(org.zmlx.hg4idea.execution.HgCommandException)

Example 3 with HgCommandException

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

the class HgTaskHandler method mergeAndClose.

@Override
protected void mergeAndClose(@NotNull final String branch, @NotNull final List<HgRepository> repositories) {
    String bookmarkRevisionArg = "bookmark(\"" + branch + "\")";
    FileDocumentManager.getInstance().saveAllDocuments();
    final UpdatedFiles updatedFiles = UpdatedFiles.create();
    for (final HgRepository repository : repositories) {
        HgMergeCommand.mergeWith(repository, bookmarkRevisionArg, updatedFiles, new Runnable() {

            @Override
            public void run() {
                Project project = repository.getProject();
                VirtualFile repositoryRoot = repository.getRoot();
                try {
                    new HgCommitCommand(project, repository, "Automated merge with " + branch).executeInCurrentThread();
                    HgBookmarkCommand.deleteBookmarkSynchronously(project, repositoryRoot, branch);
                } catch (HgCommandException e) {
                    HgErrorUtil.handleException(project, e);
                } catch (VcsException e) {
                    VcsNotifier.getInstance(project).notifyError("Exception during merge commit with " + branch, e.getMessage());
                }
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) HgCommitCommand(org.zmlx.hg4idea.command.HgCommitCommand) VcsException(com.intellij.openapi.vcs.VcsException) UpdatedFiles(com.intellij.openapi.vcs.update.UpdatedFiles) HgRepository(org.zmlx.hg4idea.repo.HgRepository) HgCommandException(org.zmlx.hg4idea.execution.HgCommandException)

Example 4 with HgCommandException

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

the class HgCheckinEnvironment method commit.

public List<VcsException> commit(List<Change> changes, String preparedComment, @NotNull NullableFunction<Object, Object> parametersHolder, Set<String> feedback) {
    List<VcsException> exceptions = new LinkedList<>();
    Map<HgRepository, Set<HgFile>> repositoriesMap = getFilesByRepository(changes);
    addRepositoriesWithoutChanges(repositoriesMap);
    for (Map.Entry<HgRepository, Set<HgFile>> entry : repositoriesMap.entrySet()) {
        HgRepository repo = entry.getKey();
        Set<HgFile> selectedFiles = entry.getValue();
        HgCommitTypeCommand command = myMqNewPatch ? new HgQNewCommand(myProject, repo, preparedComment, myNextCommitAmend) : new HgCommitCommand(myProject, repo, preparedComment, myNextCommitAmend, myCloseBranch, myShouldCommitSubrepos && !selectedFiles.isEmpty());
        if (isMergeCommit(repo.getRoot())) {
            //partial commits are not allowed during merges
            //verifyResult that all changed files in the repo are selected
            //If so, commit the entire repository
            //If not, abort
            Set<HgFile> changedFilesNotInCommit = getChangedFilesNotInCommit(repo.getRoot(), selectedFiles);
            boolean partial = !changedFilesNotInCommit.isEmpty();
            if (partial) {
                final StringBuilder filesNotIncludedString = new StringBuilder();
                for (HgFile hgFile : changedFilesNotInCommit) {
                    filesNotIncludedString.append("<li>");
                    filesNotIncludedString.append(hgFile.getRelativePath());
                    filesNotIncludedString.append("</li>");
                }
                if (!mayCommitEverything(filesNotIncludedString.toString())) {
                    //abort
                    return exceptions;
                }
                //firstly selected changes marked dirty in CommitHelper -> postRefresh, so we need to mark others
                VcsDirtyScopeManager dirtyManager = VcsDirtyScopeManager.getInstance(myProject);
                for (HgFile hgFile : changedFilesNotInCommit) {
                    dirtyManager.fileDirty(hgFile.toFilePath());
                }
            }
        // else : all was included, or it was OK to commit everything,
        // so no need to set the files on the command, because then mercurial will complain
        } else {
            command.setFiles(selectedFiles);
        }
        try {
            command.executeInCurrentThread();
        } catch (HgCommandException e) {
            exceptions.add(new VcsException(e));
        } catch (VcsException e) {
            exceptions.add(e);
        }
    }
    // push if needed
    if (myNextCommitIsPushed && exceptions.isEmpty()) {
        final List<HgRepository> preselectedRepositories = ContainerUtil.newArrayList(repositoriesMap.keySet());
        GuiUtils.invokeLaterIfNeeded(() -> new VcsPushDialog(myProject, preselectedRepositories, HgUtil.getCurrentRepository(myProject)).show(), ModalityState.defaultModalityState());
    }
    return exceptions;
}
Also used : HgQNewCommand(org.zmlx.hg4idea.command.mq.HgQNewCommand) HgCommandException(org.zmlx.hg4idea.execution.HgCommandException) VcsPushDialog(com.intellij.dvcs.push.ui.VcsPushDialog) VcsException(com.intellij.openapi.vcs.VcsException) HgRepository(org.zmlx.hg4idea.repo.HgRepository)

Example 5 with HgCommandException

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

the class HgRegularUpdater method commitOrWarnAboutConflicts.

private void commitOrWarnAboutConflicts(List<VcsException> exceptions, HgCommandResult mergeResult) throws VcsException {
    if (mergeResult.getExitValue() == 0) {
        //operation successful and no conflicts
        try {
            HgRepository hgRepository = HgUtil.getRepositoryForFile(project, repoRoot);
            if (hgRepository == null) {
                LOG.warn("Couldn't find repository info for " + repoRoot.getName());
                return;
            }
            new HgCommitCommand(project, hgRepository, "Automated merge").executeInCurrentThread();
        } catch (HgCommandException e) {
            throw new VcsException(e);
        }
    } else {
        reportWarning(exceptions, HgVcsMessages.message("hg4idea.update.warning.merge.conflicts", repoRoot.getPath()));
    }
}
Also used : VcsException(com.intellij.openapi.vcs.VcsException) HgRepository(org.zmlx.hg4idea.repo.HgRepository) HgCommandException(org.zmlx.hg4idea.execution.HgCommandException)

Aggregations

HgCommandException (org.zmlx.hg4idea.execution.HgCommandException)5 VcsException (com.intellij.openapi.vcs.VcsException)3 HgRepository (org.zmlx.hg4idea.repo.HgRepository)3 VcsPushDialog (com.intellij.dvcs.push.ui.VcsPushDialog)1 Project (com.intellij.openapi.project.Project)1 UpdatedFiles (com.intellij.openapi.vcs.update.UpdatedFiles)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 MessageBus (com.intellij.util.messages.MessageBus)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 HgFile (org.zmlx.hg4idea.HgFile)1 HgCommitCommand (org.zmlx.hg4idea.command.HgCommitCommand)1 HgQNewCommand (org.zmlx.hg4idea.command.mq.HgQNewCommand)1 HgCommandExecutor (org.zmlx.hg4idea.execution.HgCommandExecutor)1 HgRepositoryManager (org.zmlx.hg4idea.repo.HgRepositoryManager)1