Search in sources :

Example 11 with GitSimpleHandler

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

the class GitChangeUtils method commitExists.

@Nullable
public static SHAHash commitExists(final Project project, final VirtualFile root, final String anyReference, List<VirtualFile> paths, final String... parameters) {
    GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.LOG);
    h.setSilent(true);
    h.addParameters(parameters);
    h.addParameters("--max-count=1", "--pretty=%H", "--encoding=UTF-8", anyReference, "--");
    if (paths != null && !paths.isEmpty()) {
        h.addRelativeFiles(paths);
    }
    try {
        final String output = h.run().trim();
        if (StringUtil.isEmptyOrSpaces(output))
            return null;
        return new SHAHash(output);
    } catch (VcsException e) {
        return null;
    }
}
Also used : SHAHash(git4idea.history.browser.SHAHash) GitSimpleHandler(git4idea.commands.GitSimpleHandler) VcsException(com.intellij.openapi.vcs.VcsException) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with GitSimpleHandler

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

the class GitChangeUtils method getDiffHandler.

@NotNull
private static GitSimpleHandler getDiffHandler(@NotNull Project project, @NotNull VirtualFile root, @NotNull String diffRange, @Nullable Collection<FilePath> dirtyPaths, boolean reverse) {
    GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.DIFF);
    if (reverse) {
        handler.addParameters("-R");
    }
    handler.addParameters("--name-status", "--diff-filter=ADCMRUXT", "-M", diffRange);
    handler.setSilent(true);
    handler.setStdoutSuppressed(true);
    handler.endOptions();
    if (dirtyPaths != null) {
        handler.addRelativePaths(dirtyPaths);
    }
    return handler;
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler) ObjectUtils.assertNotNull(com.intellij.util.ObjectUtils.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with GitSimpleHandler

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

the class GitChangeUtils method createRefResolveHandler.

@NotNull
private static GitSimpleHandler createRefResolveHandler(@NotNull Project project, @NotNull VirtualFile root, @NotNull String reference) {
    GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.REV_LIST);
    handler.addParameters("--timestamp", "--max-count=1", reference);
    handler.endOptions();
    handler.setSilent(true);
    return handler;
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler) ObjectUtils.assertNotNull(com.intellij.util.ObjectUtils.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with GitSimpleHandler

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

the class GitChangeUtils method resolveReference.

/**
   * Load actual revision number with timestamp basing on a reference: name of a branch or tag, or revision number expression.
   */
@NotNull
public static GitRevisionNumber resolveReference(@NotNull Project project, @NotNull VirtualFile vcsRoot, @NotNull String reference) throws VcsException {
    GitSimpleHandler handler = createRefResolveHandler(project, vcsRoot, reference);
    String output = handler.run();
    StringTokenizer stk = new StringTokenizer(output, "\n\r \t", false);
    if (!stk.hasMoreTokens()) {
        try {
            GitSimpleHandler dh = new GitSimpleHandler(project, vcsRoot, GitCommand.LOG);
            dh.addParameters("-1", "HEAD");
            dh.setSilent(true);
            String out = dh.run();
            LOG.info("Diagnostic output from 'git log -1 HEAD': [" + out + "]");
            dh = createRefResolveHandler(project, vcsRoot, reference);
            out = dh.run();
            LOG.info("Diagnostic output from 'git rev-list -1 --timestamp HEAD': [" + out + "]");
        } catch (VcsException e) {
            LOG.info("Exception while trying to get some diagnostics info", e);
        }
        throw new VcsException(String.format("The string '%s' does not represent a revision number. Output: [%s]\n Root: %s", reference, output, vcsRoot));
    }
    Date timestamp = GitUtil.parseTimestampWithNFEReport(stk.nextToken(), handler, output);
    return new GitRevisionNumber(stk.nextToken(), timestamp);
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler) GitRevisionNumber(git4idea.GitRevisionNumber) VcsException(com.intellij.openapi.vcs.VcsException) ObjectUtils.assertNotNull(com.intellij.util.ObjectUtils.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with GitSimpleHandler

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

the class GitMergeDialog method updateBranches.

/**
   * Setup branches for git root, this method should be called when root is changed.
   */
public void updateBranches() throws VcsException {
    VirtualFile root = getSelectedRoot();
    GitSimpleHandler handler = new GitSimpleHandler(myProject, root, GitCommand.BRANCH);
    handler.setSilent(true);
    handler.addParameters("--no-color", "-a", "--no-merged");
    String output = handler.run();
    myBranchChooser.clear();
    for (StringTokenizer lines = new StringTokenizer(output, "\n", false); lines.hasMoreTokens(); ) {
        String branch = lines.nextToken().substring(2);
        myBranchChooser.addElement(branch, false);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StringTokenizer(java.util.StringTokenizer) GitSimpleHandler(git4idea.commands.GitSimpleHandler)

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