Search in sources :

Example 36 with GitSimpleHandler

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

the class GitFileUtils method addPaths.

private static void addPaths(@NotNull Project project, @NotNull VirtualFile root, @NotNull List<List<String>> chunkedPaths) throws VcsException {
    for (List<String> paths : chunkedPaths) {
        paths = excludeIgnoredFiles(project, root, paths);
        if (paths.isEmpty()) {
            continue;
        }
        GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.ADD);
        handler.addParameters("--ignore-errors");
        handler.endOptions();
        handler.addParameters(paths);
        handler.run();
    }
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler)

Example 37 with GitSimpleHandler

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

the class GitTag method listAsStrings.

@Deprecated
public static void listAsStrings(final Project project, final VirtualFile root, final Collection<String> tags, @Nullable final String containingCommit) throws VcsException {
    GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.TAG);
    handler.setSilent(true);
    handler.addParameters("-l");
    if (containingCommit != null) {
        handler.addParameters("--contains");
        handler.addParameters(containingCommit);
    }
    for (String line : handler.run().split("\n")) {
        if (line.length() == 0) {
            continue;
        }
        tags.add(new String(line));
    }
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler)

Example 38 with GitSimpleHandler

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

the class GitMergeProvider method getAffectedBlobs.

@NotNull
private Trinity<String, String, String> getAffectedBlobs(@NotNull VirtualFile root, @NotNull VirtualFile file) {
    try {
        GitSimpleHandler h = new GitSimpleHandler(myProject, root, GitCommand.LS_FILES);
        h.addParameters("--exclude-standard", "--unmerged", "-z");
        h.endOptions();
        h.addRelativeFiles(Collections.singleton(file));
        String output = h.run();
        StringScanner s = new StringScanner(output);
        String lastBlob = null;
        String currentBlob = null;
        String originalBlob = null;
        while (s.hasMoreData()) {
            // permissions
            s.spaceToken();
            String blob = s.spaceToken();
            // stage
            int source = Integer.parseInt(s.tabToken());
            // file name
            s.boundedToken('');
            if (source == theirsRevision(root)) {
                lastBlob = blob;
            } else if (source == yoursRevision(root)) {
                currentBlob = blob;
            } else if (source == ORIGINAL_REVISION_NUM) {
                originalBlob = blob;
            } else {
                throw new IllegalStateException("Unknown revision " + source + " for the file: " + file);
            }
        }
        return Trinity.create(currentBlob, originalBlob, lastBlob);
    } catch (VcsException e) {
        LOG.warn(e);
        return Trinity.create(null, null, null);
    }
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler) VcsException(com.intellij.openapi.vcs.VcsException) StringScanner(git4idea.util.StringScanner) NotNull(org.jetbrains.annotations.NotNull)

Example 39 with GitSimpleHandler

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

the class GitMerger method mergeCommit.

public void mergeCommit(@NotNull VirtualFile root) throws VcsException {
    GitSimpleHandler handler = new GitSimpleHandler(myProject, root, GitCommand.COMMIT);
    handler.setStdoutSuppressed(false);
    File messageFile = assertNotNull(myRepositoryManager.getRepositoryForRoot(root)).getRepositoryFiles().getMergeMessageFile();
    if (!messageFile.exists()) {
        final GitBranch branch = GitBranchUtil.getCurrentBranch(myProject, root);
        final String branchName = branch != null ? branch.getName() : "";
        handler.addParameters("-m", "Merge branch '" + branchName + "' of " + root.getPresentableUrl() + " with conflicts.");
    } else {
        handler.addParameters("-F", messageFile.getAbsolutePath());
    }
    handler.endOptions();
    handler.run();
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler) GitBranch(git4idea.GitBranch) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 40 with GitSimpleHandler

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

the class MergeChangeCollector method getChangedFilesExceptUnmerged.

/**
   * Populates the supplied collections of modified, created and removed files returned by 'git diff #revisions' command,
   * where revisions is the range of revisions to check.
   */
public void getChangedFilesExceptUnmerged(Collection<String> updated, Collection<String> created, Collection<String> removed, String revisions) throws VcsException {
    if (revisions == null) {
        return;
    }
    String root = myRoot.getPath();
    GitSimpleHandler h = new GitSimpleHandler(myProject, myRoot, GitCommand.DIFF);
    h.setSilent(true);
    // note that moves are not detected here
    h.addParameters("--name-status", "--diff-filter=ADMRUX", "--no-renames", revisions);
    for (StringScanner s = new StringScanner(h.run()); s.hasMoreData(); ) {
        if (s.isEol()) {
            s.nextLine();
            continue;
        }
        char status = s.peek();
        s.boundedToken('\t');
        final String relative = s.line();
        // eliminate conflicts
        if (myUnmergedPaths.contains(relative)) {
            continue;
        }
        String path = root + "/" + GitUtil.unescapePath(relative);
        switch(status) {
            case 'M':
                updated.add(path);
                break;
            case 'A':
                created.add(path);
                break;
            case 'D':
                removed.add(path);
                break;
            default:
                throw new IllegalStateException("Unexpected status: " + status);
        }
    }
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler) StringScanner(git4idea.util.StringScanner)

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