use of git4idea.commands.GitLineHandler in project google-cloud-intellij by GoogleCloudPlatform.
the class SetupCloudRepositoryAction method createEmptyGitRepository.
private static boolean createEmptyGitRepository(@NotNull final Project project, @NotNull VirtualFile root, @NotNull ProgressIndicator indicator) {
final GitLineHandler gitLineHandler = new GitLineHandler(project, root, GitCommand.INIT);
gitLineHandler.setStdoutSuppressed(false);
GitHandlerUtil.runInCurrentThread(gitLineHandler, indicator, true, GitBundle.getString("initializing.title"));
if (!gitLineHandler.errors().isEmpty()) {
GitUIUtil.showOperationErrors(project, gitLineHandler.errors(), "git init");
LOG.info("Failed to create empty git repo: " + gitLineHandler.errors());
return false;
}
try {
GitConfigUtil.setValue(project, root, "credential.https://source.developers.google.com.useHttpPath", "true");
} catch (VcsException ex) {
LOG.error("VcsException while setting up credential parameters (credentials will be not be cached " + "per project url)" + ex.toString());
}
GitInit.refreshAndConfigureVcsMappings(project, root, root.getPath());
try {
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
project.save();
}
}, indicator.getModalityState());
} catch (ProcessCanceledException ex) {
Thread.currentThread().interrupt();
LOG.error("ProcessCanceledException while saving project: " + ex.toString());
return false;
}
return true;
}
use of git4idea.commands.GitLineHandler in project google-cloud-intellij by GoogleCloudPlatform.
the class ProjectRepositoryValidator method unstash.
private void unstash(@NotNull final Project project, @NotNull final Ref<StashInfo> targetStash, @NotNull final VirtualFile root) {
if (repoState.getSourceRepository() == null || repoState.getOriginalBranchName() == null || (!repoState.getOriginalBranchName().equals(repoState.getSourceRepository().getCurrentBranchName()) && !repoState.getOriginalBranchName().equals(repoState.getSourceRepository().getCurrentRevision()))) {
Messages.showErrorDialog(GctBundle.getString("clouddebug.erroroncheckout", repoState.getOriginalBranchName()), "Error");
return;
}
final GitLineHandler handler = new GitLineHandler(project, root, GitCommand.STASH);
handler.addParameters("apply");
handler.addParameters("--index");
addStashParameter(project, handler, targetStash.get().getStash());
final AtomicBoolean conflict = new AtomicBoolean();
handler.addLineListener(new GitLineHandlerAdapter() {
@Override
public void onLineAvailable(String line, Key outputType) {
if (line.contains("Merge conflict")) {
conflict.set(true);
}
}
});
GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector = new GitUntrackedFilesOverwrittenByOperationDetector(root);
GitLocalChangesWouldBeOverwrittenDetector localChangesDetector = new GitLocalChangesWouldBeOverwrittenDetector(root, MERGE);
handler.addLineListener(untrackedFilesDetector);
handler.addLineListener(localChangesDetector);
AccessToken token = DvcsUtil.workingTreeChangeStarted(project);
try {
final Ref<GitCommandResult> result = Ref.create();
ProgressManager.getInstance().run(new Task.Modal(handler.project(), GitBundle.getString("unstash.unstashing"), false) {
@Override
public void run(@NotNull final ProgressIndicator indicator) {
indicator.setIndeterminate(true);
handler.addLineListener(new GitHandlerUtil.GitLineHandlerListenerProgress(indicator, handler, "stash", false));
Git git = ServiceManager.getService(Git.class);
result.set(git.runCommand(new Computable.PredefinedValueComputable<GitLineHandler>(handler)));
}
});
ServiceManager.getService(project, GitPlatformFacade.class).hardRefresh(root);
GitCommandResult res = result.get();
if (conflict.get()) {
Messages.showDialog(GctBundle.getString("clouddebug.unstashmergeconflicts"), "Merge Conflicts", new String[] { "Ok" }, 0, Messages.getErrorIcon());
} else if (untrackedFilesDetector.wasMessageDetected()) {
GitUntrackedFilesHelper.notifyUntrackedFilesOverwrittenBy(project, root, untrackedFilesDetector.getRelativeFilePaths(), "unstash", null);
} else if (localChangesDetector.wasMessageDetected()) {
LocalChangesWouldBeOverwrittenHelper.showErrorDialog(project, root, "unstash", localChangesDetector.getRelativeFilePaths());
} else if (!res.success()) {
GitUIUtil.showOperationErrors(project, handler.errors(), handler.printableCommandLine());
} else if (res.success()) {
ProgressManager.getInstance().run(new Task.Modal(project, GctBundle.getString("clouddebug.removestashx", targetStash.get().getStash()), false) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
if (project == null) {
return;
}
final GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.STASH);
h.addParameters("drop");
addStashParameter(project, h, targetStash.get().getStash());
try {
h.run();
h.unsilence();
} catch (final VcsException ex) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
GitUIUtil.showOperationError(project, ex, h.printableCommandLine());
}
});
}
}
});
}
} finally {
DvcsUtil.workingTreeChangeFinished(project, token);
}
}
Aggregations