Search in sources :

Example 6 with GitSimpleHandler

use of git4idea.commands.GitSimpleHandler in project intellij-community by JetBrains.

the class GitCheckinEnvironment method commit.

private void commit(@NotNull Project project, @NotNull VirtualFile root, @NotNull Collection<FilePath> files, @NotNull File message) throws VcsException {
    boolean amend = myNextCommitAmend;
    for (List<String> paths : VcsFileUtil.chunkPaths(root, files)) {
        GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.COMMIT);
        handler.setStdoutSuppressed(false);
        if (myNextCommitSignOff) {
            handler.addParameters("--signoff");
        }
        if (amend) {
            handler.addParameters("--amend");
        } else {
            amend = true;
        }
        handler.addParameters("--only", "-F", message.getAbsolutePath());
        if (myNextCommitAuthor != null) {
            handler.addParameters("--author=" + myNextCommitAuthor);
        }
        if (myNextCommitAuthorDate != null) {
            handler.addParameters("--date", COMMIT_DATE_FORMAT.format(myNextCommitAuthorDate));
        }
        handler.endOptions();
        handler.addParameters(paths);
        handler.run();
    }
    if (!project.isDisposed()) {
        GitRepositoryManager manager = getRepositoryManager(project);
        manager.updateRepository(root);
    }
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler) GitRepositoryManager(git4idea.repo.GitRepositoryManager) GitUtil.getLogString(git4idea.GitUtil.getLogString)

Example 7 with GitSimpleHandler

use of git4idea.commands.GitSimpleHandler in project intellij-community by JetBrains.

the class GitCheckinEnvironment method commitWithoutPaths.

private void commitWithoutPaths(@NotNull Project project, @NotNull VirtualFile root, @NotNull File messageFile, @Nullable String author) throws VcsException {
    GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.COMMIT);
    handler.setStdoutSuppressed(false);
    handler.addParameters("-F", messageFile.getAbsolutePath());
    if (author != null) {
        handler.addParameters("--author=" + author);
    }
    if (myNextCommitSignOff) {
        handler.addParameters("--signoff");
    }
    handler.endOptions();
    handler.run();
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler)

Example 8 with GitSimpleHandler

use of git4idea.commands.GitSimpleHandler in project intellij-community by JetBrains.

the class GitConfigUtil method getAllValues.

/**
   * Get configuration values for the repository. Note that the method executes a git command.
   *
   * @param project the context project
   * @param root    the git root
   * @param key     the keys to be queried
   * @return list of pairs ({@link Pair#first} is the key, {@link Pair#second} is the value)
   * @throws VcsException an exception
   */
public static List<Couple<String>> getAllValues(Project project, VirtualFile root, @NonNls String key) throws VcsException {
    List<Couple<String>> result = new ArrayList<>();
    GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.CONFIG);
    h.setSilent(true);
    h.addParameters("--null", "--get-all", key);
    String output = h.run();
    int start = 0;
    int pos;
    while ((pos = output.indexOf('', start)) != -1) {
        String value = output.substring(start, pos);
        start = pos + 1;
        result.add(Couple.of(key, value));
    }
    return result;
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler) Couple(com.intellij.openapi.util.Couple) ArrayList(java.util.ArrayList)

Example 9 with GitSimpleHandler

use of git4idea.commands.GitSimpleHandler in project intellij-community by JetBrains.

the class GitConfigUtil method getValues.

/**
   * Get configuration values for the repository. Note that the method executes a git command.
   *
   * @param project the context project
   * @param root    the git root
   * @param keyMask the keys to be queried
   * @param result  the map to put results to
   * @throws VcsException if there is a problem with running git
   */
public static void getValues(Project project, VirtualFile root, String keyMask, Map<String, String> result) throws VcsException {
    GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.CONFIG);
    h.setSilent(true);
    h.addParameters("--null");
    if (keyMask != null) {
        h.addParameters("--get-regexp", keyMask);
    } else {
        h.addParameters("-l");
    }
    String output = h.run();
    int start = 0;
    int pos;
    while ((pos = output.indexOf('\n', start)) != -1) {
        String key = output.substring(start, pos);
        start = pos + 1;
        if ((pos = output.indexOf('', start)) == -1) {
            break;
        }
        String value = output.substring(start, pos);
        start = pos + 1;
        result.put(key, value);
    }
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler)

Example 10 with GitSimpleHandler

use of git4idea.commands.GitSimpleHandler in project intellij-community by JetBrains.

the class GitConfigUtil method getValue.

/**
   * Get configuration value for the repository. Note that the method executes a git command.
   *
   * @param project the context project
   * @param root    the git root
   * @param key     the keys to be queried
   * @return the value associated with the key or null if the value is not found
   * @throws VcsException an exception
   */
@Nullable
public static String getValue(Project project, VirtualFile root, @NonNls String key) throws VcsException {
    GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.CONFIG);
    h.setSilent(true);
    h.ignoreErrorCode(1);
    h.addParameters("--null", "--get", key);
    String output = h.run();
    int pos = output.indexOf('');
    if (h.getExitCode() != 0 || pos == -1) {
        return null;
    }
    return output.substring(0, pos);
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GitSimpleHandler (git4idea.commands.GitSimpleHandler)42 NotNull (org.jetbrains.annotations.NotNull)10 VcsException (com.intellij.openapi.vcs.VcsException)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 ObjectUtils.assertNotNull (com.intellij.util.ObjectUtils.assertNotNull)6 StringScanner (git4idea.util.StringScanner)5 FilePath (com.intellij.openapi.vcs.FilePath)3 Change (com.intellij.openapi.vcs.changes.Change)3 GitRevisionNumber (git4idea.GitRevisionNumber)3 File (java.io.File)3 Nullable (org.jetbrains.annotations.Nullable)3 GitUtil.getLogString (git4idea.GitUtil.getLogString)2 GitRepositoryManager (git4idea.repo.GitRepositoryManager)2 Couple (com.intellij.openapi.util.Couple)1 Pair (com.intellij.openapi.util.Pair)1 Ref (com.intellij.openapi.util.Ref)1 SelectFilePathsDialog (com.intellij.openapi.vcs.changes.ui.SelectFilePathsDialog)1 VcsVirtualFile (com.intellij.openapi.vcs.vfs.VcsVirtualFile)1 Convertor (com.intellij.util.containers.Convertor)1 GitBranch (git4idea.GitBranch)1