Search in sources :

Example 6 with GitLineHandler

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

the class GitResetDialog method handler.

/**
   * @return the handler for reset operation
   */
public GitLineHandler handler() {
    GitLineHandler handler = new GitLineHandler(myProject, getGitRoot(), GitCommand.RESET);
    String type = (String) myResetTypeComboBox.getSelectedItem();
    if (SOFT.equals(type)) {
        handler.addParameters("--soft");
    } else if (HARD.equals(type)) {
        handler.addParameters("--hard");
    } else if (MIXED.equals(type)) {
        handler.addParameters("--mixed");
    }
    final String commit = myCommitTextField.getText().trim();
    if (commit.length() != 0) {
        handler.addParameters(commit);
    }
    handler.endOptions();
    return handler;
}
Also used : GitLineHandler(git4idea.commands.GitLineHandler)

Example 7 with GitLineHandler

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

the class GitMerge method displayDialog.

@Nullable
@Override
protected DialogState displayDialog(@NotNull Project project, @NotNull List<VirtualFile> gitRoots, @NotNull VirtualFile defaultRoot) {
    GitVcs vcs = GitVcs.getInstance(project);
    if (vcs == null) {
        return null;
    }
    final GitMergeDialog dialog = new GitMergeDialog(project, gitRoots, defaultRoot);
    try {
        dialog.updateBranches();
    } catch (VcsException e) {
        if (vcs.getExecutableValidator().checkExecutableAndShowMessageIfNeeded(null)) {
            vcs.showErrors(Collections.singletonList(e), GitBundle.getString("merge.retrieving.branches"));
        }
        return null;
    }
    if (!dialog.showAndGet()) {
        return null;
    }
    return new DialogState(dialog.getSelectedRoot(), GitBundle.message("merging.title", dialog.getSelectedRoot().getPath()), new Computable<GitLineHandler>() {

        @Override
        public GitLineHandler compute() {
            return dialog.handler();
        }
    });
}
Also used : GitVcs(git4idea.GitVcs) GitLineHandler(git4idea.commands.GitLineHandler) GitMergeDialog(git4idea.merge.GitMergeDialog) VcsException(com.intellij.openapi.vcs.VcsException) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with GitLineHandler

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

the class GitPull method displayDialog.

@Override
protected DialogState displayDialog(@NotNull Project project, @NotNull List<VirtualFile> gitRoots, @NotNull VirtualFile defaultRoot) {
    final GitPullDialog dialog = new GitPullDialog(project, gitRoots, defaultRoot);
    if (!dialog.showAndGet()) {
        return null;
    }
    GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(project);
    GitRepository repository = repositoryManager.getRepositoryForRoot(dialog.gitRoot());
    assert repository != null : "Repository can't be null for root " + dialog.gitRoot();
    String remoteOrUrl = dialog.getRemote();
    if (remoteOrUrl == null) {
        return null;
    }
    GitRemote remote = GitUtil.findRemoteByName(repository, remoteOrUrl);
    final List<String> urls = remote == null ? Collections.singletonList(remoteOrUrl) : remote.getUrls();
    Computable<GitLineHandler> handlerProvider = new Computable<GitLineHandler>() {

        @Override
        public GitLineHandler compute() {
            return dialog.makeHandler(urls);
        }
    };
    return new DialogState(dialog.gitRoot(), GitBundle.message("pulling.title", dialog.getRemote()), handlerProvider);
}
Also used : GitRemote(git4idea.repo.GitRemote) GitRepository(git4idea.repo.GitRepository) GitPullDialog(git4idea.merge.GitPullDialog) GitLineHandler(git4idea.commands.GitLineHandler) GitRepositoryManager(git4idea.repo.GitRepositoryManager) Computable(com.intellij.openapi.util.Computable)

Example 9 with GitLineHandler

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

the class GitMergeDialog method handler.

/**
   * @return get line handler configured according to the selected options
   */
public GitLineHandler handler() {
    if (!isOK()) {
        throw new IllegalStateException("The handler could be retrieved only if dialog was completed successfully.");
    }
    VirtualFile root = (VirtualFile) myGitRoot.getSelectedItem();
    GitLineHandler h = new GitLineHandler(myProject, root, GitCommand.MERGE);
    if (myNoCommitCheckBox.isSelected()) {
        h.addParameters("--no-commit");
    }
    if (myAddLogInformationCheckBox.isSelected()) {
        h.addParameters("--log");
    }
    final String msg = myCommitMessage.getText().trim();
    if (msg.length() != 0) {
        h.addParameters("-m", msg);
    }
    if (mySquashCommitCheckBox.isSelected()) {
        h.addParameters("--squash");
    }
    if (myNoFastForwardCheckBox.isSelected()) {
        h.addParameters("--no-ff");
    }
    String strategy = (String) myStrategy.getSelectedItem();
    if (!GitMergeUtil.DEFAULT_STRATEGY.equals(strategy)) {
        h.addParameters("--strategy", strategy);
    }
    for (String branch : myBranchChooser.getMarkedElements()) {
        h.addParameters(branch);
    }
    return h;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitLineHandler(git4idea.commands.GitLineHandler)

Example 10 with GitLineHandler

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

the class GitMergeProvider method doGetBlobPathInRevision.

@Nullable
private FilePath doGetBlobPathInRevision(@NotNull final VirtualFile root, @NotNull final String blob, @NotNull VcsRevisionNumber revision, @Nullable VirtualFile file) {
    final FilePath[] result = new FilePath[1];
    final boolean[] pathAmbiguous = new boolean[1];
    GitLineHandler h = new GitLineHandler(myProject, root, GitCommand.LS_TREE);
    h.addParameters(revision.asString());
    if (file != null) {
        h.endOptions();
        h.addRelativeFiles(Collections.singleton(file));
    } else {
        h.addParameters("-r");
        h.endOptions();
    }
    h.addLineListener(new GitLineHandlerAdapter() {

        @Override
        public void onLineAvailable(String line, Key outputType) {
            if (outputType != ProcessOutputTypes.STDOUT)
                return;
            if (!line.contains(blob))
                return;
            if (pathAmbiguous[0])
                return;
            try {
                StringScanner s = new StringScanner(line);
                // permissions
                s.spaceToken();
                // type
                String type = s.spaceToken();
                // blob
                String recordBlob = s.tabToken();
                FilePath file = VcsUtil.getFilePath(root, GitUtil.unescapePath(s.line()));
                if (!"blob".equals(type))
                    return;
                if (!blob.equals(recordBlob))
                    return;
                if (result[0] == null) {
                    result[0] = file;
                } else {
                    // there are multiple files with given content in this revision.
                    // we don't know which is right, so do not return any
                    pathAmbiguous[0] = true;
                }
            } catch (VcsException e) {
                LOG.warn(e);
            }
        }
    });
    h.runInCurrentThread(null);
    if (pathAmbiguous[0])
        return null;
    return result[0];
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) GitLineHandler(git4idea.commands.GitLineHandler) VcsException(com.intellij.openapi.vcs.VcsException) GitLineHandlerAdapter(git4idea.commands.GitLineHandlerAdapter) StringScanner(git4idea.util.StringScanner) Key(com.intellij.openapi.util.Key) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GitLineHandler (git4idea.commands.GitLineHandler)12 AccessToken (com.intellij.openapi.application.AccessToken)4 VcsException (com.intellij.openapi.vcs.VcsException)4 Computable (com.intellij.openapi.util.Computable)2 Key (com.intellij.openapi.util.Key)2 ChangeListManager (com.intellij.openapi.vcs.changes.ChangeListManager)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 GitLineHandlerAdapter (git4idea.commands.GitLineHandlerAdapter)2 GitRepositoryManager (git4idea.repo.GitRepositoryManager)2 Nullable (org.jetbrains.annotations.Nullable)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 FilePath (com.intellij.openapi.vcs.FilePath)1 GitPlatformFacade (git4idea.GitPlatformFacade)1 GitVcs (git4idea.GitVcs)1 Git (git4idea.commands.Git)1 GitCommandResult (git4idea.commands.GitCommandResult)1 GitLocalChangesWouldBeOverwrittenDetector (git4idea.commands.GitLocalChangesWouldBeOverwrittenDetector)1 GitSimpleHandler (git4idea.commands.GitSimpleHandler)1