Search in sources :

Example 16 with GitSimpleHandler

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

the class GitRollbackEnvironment method revert.

/**
   * Reverts the list of files we are passed.
   *
   * @param root  the VCS root
   * @param files The array of files to revert.
   * @throws VcsException Id it breaks.
   */
public void revert(final VirtualFile root, final List<FilePath> files) throws VcsException {
    for (List<String> paths : VcsFileUtil.chunkPaths(root, files)) {
        GitSimpleHandler handler = new GitSimpleHandler(myProject, root, GitCommand.CHECKOUT);
        handler.addParameters("HEAD");
        handler.endOptions();
        handler.addParameters(paths);
        handler.run();
    }
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler)

Example 17 with GitSimpleHandler

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

the class MergeChangeCollector method getUnmergedPaths.

/**
   * Returns absolute paths to files which are currently unmerged, and also populates myUnmergedPaths with relative paths.
   */
@NotNull
public Set<String> getUnmergedPaths() throws VcsException {
    String root = myRoot.getPath();
    final GitSimpleHandler h = new GitSimpleHandler(myProject, myRoot, GitCommand.LS_FILES);
    h.setSilent(true);
    h.addParameters("--unmerged");
    final String result = h.run();
    final Set<String> paths = new HashSet<>();
    for (StringScanner s = new StringScanner(result); s.hasMoreData(); ) {
        if (s.isEol()) {
            s.nextLine();
            continue;
        }
        s.boundedToken('\t');
        final String relative = s.line();
        if (!myUnmergedPaths.add(relative)) {
            continue;
        }
        String path = root + "/" + GitUtil.unescapePath(relative);
        paths.add(path);
    }
    return paths;
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler) StringScanner(git4idea.util.StringScanner) ObjectUtils.assertNotNull(com.intellij.util.ObjectUtils.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with GitSimpleHandler

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

the class GitStashUtils method loadStashStack.

public static void loadStashStack(@NotNull Project project, @NotNull VirtualFile root, @NotNull Charset charset, final Consumer<StashInfo> consumer) {
    GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.STASH.readLockingCommand());
    h.setSilent(true);
    h.addParameters("list");
    String out;
    try {
        h.setCharset(charset);
        out = h.run();
    } catch (VcsException e) {
        GitUIUtil.showOperationError(project, e, h.printableCommandLine());
        return;
    }
    for (StringScanner s = new StringScanner(out); s.hasMoreData(); ) {
        consumer.consume(new StashInfo(s.boundedToken(':'), s.boundedToken(':'), s.line().trim()));
    }
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler) VcsException(com.intellij.openapi.vcs.VcsException) StringScanner(git4idea.util.StringScanner) StashInfo(git4idea.ui.StashInfo)

Example 19 with GitSimpleHandler

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

the class GitOldChangesCollector method collectDiffChanges.

/**
   * Collect diff with head
   *
   * @throws VcsException if there is a problem with running git
   */
private void collectDiffChanges() throws VcsException {
    Collection<FilePath> dirtyPaths = dirtyPaths(true);
    if (dirtyPaths.isEmpty()) {
        return;
    }
    try {
        String output = GitChangeUtils.getDiffOutput(myProject, myVcsRoot, "HEAD", dirtyPaths);
        GitChangeUtils.parseChanges(myProject, myVcsRoot, null, GitChangeUtils.resolveReference(myProject, myVcsRoot, "HEAD"), output, myChanges, myUnmergedNames);
    } catch (VcsException ex) {
        if (!GitChangeUtils.isHeadMissing(ex)) {
            throw ex;
        }
        GitSimpleHandler handler = new GitSimpleHandler(myProject, myVcsRoot, GitCommand.LS_FILES);
        handler.addParameters("--cached");
        handler.setSilent(true);
        handler.setStdoutSuppressed(true);
        // During init diff does not works because HEAD
        // will appear only after the first commit.
        // In that case added files are cached in index.
        String output = handler.run();
        if (output.length() > 0) {
            StringTokenizer tokenizer = new StringTokenizer(output, "\n\r");
            while (tokenizer.hasMoreTokens()) {
                final String s = tokenizer.nextToken();
                Change ch = new Change(null, GitContentRevision.createRevision(myVcsRoot, s, null, myProject, false, false, true), FileStatus.ADDED);
                myChanges.add(ch);
            }
        }
    }
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler) Change(com.intellij.openapi.vcs.changes.Change)

Example 20 with GitSimpleHandler

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

the class GitOldChangesCollector method updateIndex.

private void updateIndex() throws VcsException {
    GitSimpleHandler handler = new GitSimpleHandler(myProject, myVcsRoot, GitCommand.UPDATE_INDEX);
    handler.addParameters("--refresh", "--ignore-missing");
    handler.setSilent(true);
    handler.setStdoutSuppressed(true);
    handler.ignoreErrorCode(1);
    handler.run();
}
Also used : 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