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;
}
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();
}
});
}
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);
}
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;
}
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];
}
Aggregations