Search in sources :

Example 1 with SelectFilePathsDialog

use of com.intellij.openapi.vcs.changes.ui.SelectFilePathsDialog in project intellij-community by JetBrains.

the class GitCheckinEnvironment method mergeCommit.

/**
   * Preform a merge commit
   *
   * @param project          a project
   * @param root             a vcs root
   * @param added            added files
   * @param removed          removed files
   * @param messageFile      a message file for commit
   * @param author           an author
   * @param exceptions       the list of exceptions to report
   * @param partialOperation
   * @return true if merge commit was successful
   */
private boolean mergeCommit(final Project project, final VirtualFile root, final Set<FilePath> added, final Set<FilePath> removed, final File messageFile, final String author, List<VcsException> exceptions, @NotNull final PartialOperation partialOperation) {
    HashSet<FilePath> realAdded = new HashSet<>();
    HashSet<FilePath> realRemoved = new HashSet<>();
    // perform diff
    GitSimpleHandler diff = new GitSimpleHandler(project, root, GitCommand.DIFF);
    diff.setSilent(true);
    diff.setStdoutSuppressed(true);
    diff.addParameters("--diff-filter=ADMRUX", "--name-status", "--no-renames", "HEAD");
    diff.endOptions();
    String output;
    try {
        output = diff.run();
    } catch (VcsException ex) {
        exceptions.add(ex);
        return false;
    }
    String rootPath = root.getPath();
    for (StringTokenizer lines = new StringTokenizer(output, "\n", false); lines.hasMoreTokens(); ) {
        String line = lines.nextToken().trim();
        if (line.length() == 0) {
            continue;
        }
        String[] tk = line.split("\t");
        switch(tk[0].charAt(0)) {
            case 'M':
            case 'A':
                realAdded.add(VcsUtil.getFilePath(rootPath + "/" + tk[1]));
                break;
            case 'D':
                realRemoved.add(VcsUtil.getFilePathForDeletedFile(rootPath + "/" + tk[1], false));
                break;
            default:
                throw new IllegalStateException("Unexpected status: " + line);
        }
    }
    realAdded.removeAll(added);
    realRemoved.removeAll(removed);
    if (realAdded.size() != 0 || realRemoved.size() != 0) {
        final List<FilePath> files = new ArrayList<>();
        files.addAll(realAdded);
        files.addAll(realRemoved);
        final Ref<Boolean> mergeAll = new Ref<>();
        try {
            GuiUtils.runOrInvokeAndWait(new Runnable() {

                public void run() {
                    String message = GitBundle.message("commit.partial.merge.message", partialOperation.getName());
                    SelectFilePathsDialog dialog = new SelectFilePathsDialog(project, files, message, null, "Commit All Files", CommonBundle.getCancelButtonText(), false);
                    dialog.setTitle(GitBundle.getString("commit.partial.merge.title"));
                    dialog.show();
                    mergeAll.set(dialog.isOK());
                }
            });
        } catch (RuntimeException ex) {
            throw ex;
        } catch (Exception ex) {
            throw new RuntimeException("Unable to invoke a message box on AWT thread", ex);
        }
        if (!mergeAll.get()) {
            return false;
        }
        // update non-indexed files
        if (!updateIndex(project, root, realAdded, realRemoved, exceptions)) {
            return false;
        }
        for (FilePath f : realAdded) {
            VcsDirtyScopeManager.getInstance(project).fileDirty(f);
        }
        for (FilePath f : realRemoved) {
            VcsDirtyScopeManager.getInstance(project).fileDirty(f);
        }
    }
    // perform merge commit
    try {
        commitWithoutPaths(project, root, messageFile, author);
        GitRepositoryManager manager = getRepositoryManager(project);
        manager.updateRepository(root);
    } catch (VcsException ex) {
        exceptions.add(ex);
        return false;
    }
    return true;
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) GitSimpleHandler(git4idea.commands.GitSimpleHandler) GitRepositoryManager(git4idea.repo.GitRepositoryManager) GitUtil.getLogString(git4idea.GitUtil.getLogString) VcsException(com.intellij.openapi.vcs.VcsException) SelectFilePathsDialog(com.intellij.openapi.vcs.changes.ui.SelectFilePathsDialog) Ref(com.intellij.openapi.util.Ref) VcsException(com.intellij.openapi.vcs.VcsException)

Aggregations

Ref (com.intellij.openapi.util.Ref)1 FilePath (com.intellij.openapi.vcs.FilePath)1 VcsException (com.intellij.openapi.vcs.VcsException)1 SelectFilePathsDialog (com.intellij.openapi.vcs.changes.ui.SelectFilePathsDialog)1 GitUtil.getLogString (git4idea.GitUtil.getLogString)1 GitSimpleHandler (git4idea.commands.GitSimpleHandler)1 GitRepositoryManager (git4idea.repo.GitRepositoryManager)1