use of git4idea.commands.Git in project intellij-community by JetBrains.
the class GithubCheckoutProvider method doCheckout.
@Override
public void doCheckout(@NotNull final Project project, @Nullable final Listener listener) {
if (!GithubUtil.testGitExecutable(project)) {
return;
}
BasicAction.saveAll();
List<GithubRepo> availableRepos;
try {
availableRepos = GithubUtil.computeValueInModalIO(project, "Access to GitHub", indicator -> GithubUtil.runTask(project, GithubAuthDataHolder.createFromSettings(), indicator, connection -> GithubApiUtil.getAvailableRepos(connection)));
} catch (IOException e) {
GithubNotifications.showError(project, "Couldn't get the list of GitHub repositories", e);
return;
}
Collections.sort(availableRepos, (r1, r2) -> {
final int comparedOwners = r1.getUserName().compareTo(r2.getUserName());
return comparedOwners != 0 ? comparedOwners : r1.getName().compareTo(r2.getName());
});
final GitCloneDialog dialog = new GitCloneDialog(project);
// Add predefined repositories to history
dialog.prependToHistory("-----------------------------------------------");
for (int i = availableRepos.size() - 1; i >= 0; i--) {
dialog.prependToHistory(GithubUrlUtil.getCloneUrl(availableRepos.get(i).getFullPath()));
}
if (!dialog.showAndGet()) {
return;
}
dialog.rememberSettings();
final VirtualFile destinationParent = LocalFileSystem.getInstance().findFileByIoFile(new File(dialog.getParentDirectory()));
if (destinationParent == null) {
return;
}
final String sourceRepositoryURL = dialog.getSourceRepositoryURL();
final String directoryName = dialog.getDirectoryName();
final String parentDirectory = dialog.getParentDirectory();
Git git = ServiceManager.getService(Git.class);
GitCheckoutProvider.clone(project, git, listener, destinationParent, sourceRepositoryURL, directoryName, parentDirectory);
}
use of git4idea.commands.Git in project google-cloud-intellij by GoogleCloudPlatform.
the class SetupCloudRepositoryAction method pushCurrentBranch.
private static boolean pushCurrentBranch(@NotNull final Project project, @NotNull GitRepository repository, @NotNull String remoteName, @NotNull String remoteUrl) {
Git git = ServiceManager.getService(Git.class);
GitLocalBranch currentBranch = repository.getCurrentBranch();
if (currentBranch == null) {
SwingUtilities.invokeLater(() -> {
Notification notification = new Notification(NOTIFICATION_GROUP_ID, GctBundle.message("uploadtogcp.initialpushfailedtitle"), GctBundle.message("uploadtogcp.initialpushfailed"), NotificationType.ERROR);
notification.notify(project);
});
return false;
}
GitCommandResult result = git.push(repository, remoteName, remoteUrl, currentBranch.getName(), true);
if (!result.success()) {
LOG.warn(result.getErrorOutputAsJoinedString());
SwingUtilities.invokeLater(() -> {
Notification notification = new Notification(NOTIFICATION_GROUP_ID, GctBundle.message("uploadtogcp.initialpushfailedtitle"), result.getErrorOutputAsHtmlString() + "<br/>" + joinAsErrorHtmlString(result.getOutput()), NotificationType.ERROR);
notification.notify(project);
});
return false;
}
return true;
}
use of git4idea.commands.Git in project intellij-community by JetBrains.
the class GitFetcher method fetchNatively.
@NotNull
private static GitFetchResult fetchNatively(@NotNull GitRepository repository, @NotNull GitRemote remote, @Nullable String branch) {
Git git = Git.getInstance();
String[] additionalParams = branch != null ? new String[] { getFetchSpecForBranch(branch, remote.getName()) } : ArrayUtil.EMPTY_STRING_ARRAY;
GitFetchPruneDetector pruneDetector = new GitFetchPruneDetector();
GitCommandResult result = git.fetch(repository, remote, Collections.<GitLineHandlerListener>singletonList(pruneDetector), additionalParams);
GitFetchResult fetchResult;
if (result.success()) {
fetchResult = GitFetchResult.success();
} else if (result.cancelled()) {
fetchResult = GitFetchResult.cancel();
} else {
fetchResult = GitFetchResult.error(result.getErrorOutputAsJoinedString());
}
fetchResult.addPruneInfo(pruneDetector.getPrunedRefs());
return fetchResult;
}
use of git4idea.commands.Git in project intellij-community by JetBrains.
the class GithubCreatePullRequestWorker method create.
@Nullable
public static GithubCreatePullRequestWorker create(@NotNull final Project project, @Nullable final VirtualFile file) {
return GithubUtil.computeValueInModal(project, "Loading data...", indicator -> {
Git git = ServiceManager.getService(Git.class);
GitRepository gitRepository = GithubUtil.getGitRepository(project, file);
if (gitRepository == null) {
GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, "Can't find git repository");
return null;
}
gitRepository.update();
Pair<GitRemote, String> remote = GithubUtil.findGithubRemote(gitRepository);
if (remote == null) {
GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, "Can't find GitHub remote");
return null;
}
String remoteName = remote.getFirst().getName();
String remoteUrl = remote.getSecond();
GithubFullPath path = GithubUrlUtil.getUserAndRepositoryFromRemoteUrl(remoteUrl);
if (path == null) {
GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, "Can't process remote: " + remoteUrl);
return null;
}
GitLocalBranch currentBranch = gitRepository.getCurrentBranch();
if (currentBranch == null) {
GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, "No current branch");
return null;
}
GithubAuthDataHolder authHolder;
try {
authHolder = GithubUtil.getValidAuthDataHolderFromConfig(project, AuthLevel.LOGGED, indicator);
} catch (IOException e) {
GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, e);
return null;
}
GithubCreatePullRequestWorker worker = new GithubCreatePullRequestWorker(project, git, gitRepository, authHolder, path, remoteName, remoteUrl, currentBranch.getName());
try {
worker.initForks(indicator);
} catch (IOException e) {
GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, e);
return null;
}
return worker;
});
}
use of git4idea.commands.Git 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