Search in sources :

Example 1 with VcsPushDialog

use of com.intellij.dvcs.push.ui.VcsPushDialog in project intellij-community by JetBrains.

the class GitCheckinEnvironment method commit.

public List<VcsException> commit(@NotNull List<Change> changes, @NotNull String message, @NotNull NullableFunction<Object, Object> parametersHolder, Set<String> feedback) {
    List<VcsException> exceptions = new ArrayList<>();
    Map<VirtualFile, Collection<Change>> sortedChanges = sortChangesByGitRoot(changes, exceptions);
    LOG.assertTrue(!sortedChanges.isEmpty(), "Trying to commit an empty list of changes: " + changes);
    for (Map.Entry<VirtualFile, Collection<Change>> entry : sortedChanges.entrySet()) {
        VirtualFile root = entry.getKey();
        File messageFile;
        try {
            messageFile = createMessageFile(root, message);
        } catch (IOException ex) {
            //noinspection ThrowableInstanceNeverThrown
            exceptions.add(new VcsException("Creation of commit message file failed", ex));
            continue;
        }
        Set<FilePath> added = new HashSet<>();
        Set<FilePath> removed = new HashSet<>();
        final Set<Change> caseOnlyRenames = new HashSet<>();
        for (Change change : entry.getValue()) {
            switch(change.getType()) {
                case NEW:
                case MODIFICATION:
                    added.add(change.getAfterRevision().getFile());
                    break;
                case DELETED:
                    removed.add(change.getBeforeRevision().getFile());
                    break;
                case MOVED:
                    FilePath afterPath = change.getAfterRevision().getFile();
                    FilePath beforePath = change.getBeforeRevision().getFile();
                    if (!SystemInfo.isFileSystemCaseSensitive && GitUtil.isCaseOnlyChange(beforePath.getPath(), afterPath.getPath())) {
                        caseOnlyRenames.add(change);
                    } else {
                        added.add(afterPath);
                        removed.add(beforePath);
                    }
                    break;
                default:
                    throw new IllegalStateException("Unknown change type: " + change.getType());
            }
        }
        try {
            if (!caseOnlyRenames.isEmpty()) {
                List<VcsException> exs = commitWithCaseOnlyRename(myProject, root, caseOnlyRenames, added, removed, messageFile, myNextCommitAuthor);
                exceptions.addAll(map(exs, GitCheckinEnvironment::cleanupExceptionText));
            } else {
                try {
                    Set<FilePath> files = new HashSet<>();
                    files.addAll(added);
                    files.addAll(removed);
                    commit(myProject, root, files, messageFile);
                } catch (VcsException ex) {
                    PartialOperation partialOperation = isMergeCommit(ex);
                    if (partialOperation == PartialOperation.NONE) {
                        throw ex;
                    }
                    if (!mergeCommit(myProject, root, added, removed, messageFile, myNextCommitAuthor, exceptions, partialOperation)) {
                        throw ex;
                    }
                }
            }
        } catch (VcsException e) {
            exceptions.add(cleanupExceptionText(e));
        } finally {
            if (!messageFile.delete()) {
                LOG.warn("Failed to remove temporary file: " + messageFile);
            }
        }
    }
    if (myNextCommitIsPushed != null && myNextCommitIsPushed.booleanValue() && exceptions.isEmpty()) {
        GitRepositoryManager manager = getRepositoryManager(myProject);
        Collection<GitRepository> repositories = GitUtil.getRepositoriesFromRoots(manager, sortedChanges.keySet());
        final List<GitRepository> preselectedRepositories = newArrayList(repositories);
        GuiUtils.invokeLaterIfNeeded(() -> new VcsPushDialog(myProject, preselectedRepositories, GitBranchUtil.getCurrentRepository(myProject)).show(), ModalityState.defaultModalityState());
    }
    return exceptions;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FilePath(com.intellij.openapi.vcs.FilePath) GitRepositoryManager(git4idea.repo.GitRepositoryManager) GitRepository(git4idea.repo.GitRepository) VcsPushDialog(com.intellij.dvcs.push.ui.VcsPushDialog) VcsException(com.intellij.openapi.vcs.VcsException) VirtualFile(com.intellij.openapi.vfs.VirtualFile)

Example 2 with VcsPushDialog

use of com.intellij.dvcs.push.ui.VcsPushDialog in project intellij-community by JetBrains.

the class VcsPushAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    VcsRepositoryManager manager = VcsRepositoryManager.getInstance(project);
    Collection<Repository> repositories = e.getData(CommonDataKeys.EDITOR) != null ? ContainerUtil.<Repository>emptyList() : collectRepositories(manager, e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY));
    VirtualFile selectedFile = DvcsUtil.getSelectedFile(project);
    new VcsPushDialog(project, DvcsUtil.sortRepositories(repositories), selectedFile != null ? manager.getRepositoryForFile(selectedFile) : null).show();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Repository(com.intellij.dvcs.repo.Repository) VcsPushDialog(com.intellij.dvcs.push.ui.VcsPushDialog) VcsRepositoryManager(com.intellij.dvcs.repo.VcsRepositoryManager)

Example 3 with VcsPushDialog

use of com.intellij.dvcs.push.ui.VcsPushDialog 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)

Aggregations

VcsPushDialog (com.intellij.dvcs.push.ui.VcsPushDialog)3 VcsException (com.intellij.openapi.vcs.VcsException)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Repository (com.intellij.dvcs.repo.Repository)1 VcsRepositoryManager (com.intellij.dvcs.repo.VcsRepositoryManager)1 Project (com.intellij.openapi.project.Project)1 FilePath (com.intellij.openapi.vcs.FilePath)1 GitRepository (git4idea.repo.GitRepository)1 GitRepositoryManager (git4idea.repo.GitRepositoryManager)1 HgQNewCommand (org.zmlx.hg4idea.command.mq.HgQNewCommand)1 HgCommandException (org.zmlx.hg4idea.execution.HgCommandException)1 HgRepository (org.zmlx.hg4idea.repo.HgRepository)1