Search in sources :

Example 21 with GitSimpleHandler

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

the class GitFileUtils method excludeIgnoredFiles.

@NotNull
private static List<String> excludeIgnoredFiles(@NotNull Project project, @NotNull VirtualFile root, @NotNull List<String> paths) throws VcsException {
    GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.LS_FILES);
    handler.setSilent(true);
    handler.addParameters("--ignored", "--others", "--exclude-standard");
    handler.endOptions();
    handler.addParameters(paths);
    String output = handler.run();
    List<String> nonIgnoredFiles = new ArrayList<>(paths.size());
    Set<String> ignoredPaths = new HashSet<>(Arrays.asList(StringUtil.splitByLines(output)));
    for (String pathToCheck : paths) {
        if (!ignoredPaths.contains(pathToCheck)) {
            nonIgnoredFiles.add(pathToCheck);
        }
    }
    return nonIgnoredFiles;
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with GitSimpleHandler

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

the class GitFileUtils method doDelete.

private static void doDelete(@NotNull Project project, @NotNull VirtualFile root, @NotNull List<String> paths, String... additionalOptions) throws VcsException {
    GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.RM);
    handler.addParameters(additionalOptions);
    handler.endOptions();
    handler.addParameters(paths);
    handler.run();
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler)

Example 23 with GitSimpleHandler

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

the class GitVFSListener method performForceMove.

private void performForceMove(@NotNull List<MovedFileInfo> files) {
    Map<FilePath, MovedFileInfo> filesToMove = map2Map(files, (info) -> Pair.create(VcsUtil.getFilePath(info.myNewPath), info));
    Set<File> toRefresh = newHashSet();
    performBackgroundOperation(filesToMove.keySet(), "Moving Files...", new LongOperationPerRootExecutor() {

        @Override
        public void execute(@NotNull VirtualFile root, @NotNull List<FilePath> files) throws VcsException {
            for (FilePath file : files) {
                GitHandler h = new GitSimpleHandler(myProject, root, GitCommand.MV);
                MovedFileInfo info = filesToMove.get(file);
                h.addParameters("-f", info.myOldPath, info.myNewPath);
                h.runInCurrentThread(null);
                toRefresh.add(new File(info.myOldPath));
                toRefresh.add(new File(info.myNewPath));
            }
        }

        @Override
        public Collection<File> getFilesToRefresh() {
            return toRefresh;
        }
    });
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitSimpleHandler(git4idea.commands.GitSimpleHandler) GitHandler(git4idea.commands.GitHandler) VcsException(com.intellij.openapi.vcs.VcsException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 24 with GitSimpleHandler

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

the class GithubUtil method addGithubRemote.

public static boolean addGithubRemote(@NotNull Project project, @NotNull GitRepository repository, @NotNull String remote, @NotNull String url) {
    final GitSimpleHandler handler = new GitSimpleHandler(project, repository.getRoot(), GitCommand.REMOTE);
    handler.setSilent(true);
    try {
        handler.addParameters("add", remote, url);
        handler.run();
        if (handler.getExitCode() != 0) {
            GithubNotifications.showError(project, "Can't add remote", "Failed to add GitHub remote: '" + url + "'. " + handler.getStderr());
            return false;
        }
        // catch newly added remote
        repository.update();
        return true;
    } catch (VcsException e) {
        GithubNotifications.showError(project, "Can't add remote", e);
        return false;
    }
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler) VcsException(com.intellij.openapi.vcs.VcsException)

Example 25 with GitSimpleHandler

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

the class GitUpdater method hasRemoteChanges.

protected boolean hasRemoteChanges(@NotNull String remoteBranch) throws VcsException {
    GitSimpleHandler handler = new GitSimpleHandler(myProject, myRoot, GitCommand.REV_LIST);
    handler.setSilent(true);
    handler.addParameters("-1");
    handler.addParameters(HEAD + ".." + remoteBranch);
    String output = handler.run();
    return output != null && !output.isEmpty();
}
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