use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GithubRebaseAction method update.
public void update(AnActionEvent e) {
final Project project = e.getData(CommonDataKeys.PROJECT);
final VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE);
if (project == null || project.isDefault()) {
e.getPresentation().setEnabledAndVisible(false);
return;
}
final GitRepository gitRepository = GithubUtil.getGitRepository(project, file);
if (gitRepository == null) {
e.getPresentation().setEnabledAndVisible(false);
return;
}
if (!GithubUtil.isRepositoryOnGitHub(gitRepository)) {
e.getPresentation().setEnabledAndVisible(false);
return;
}
e.getPresentation().setEnabledAndVisible(true);
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GithubShareAction method shareProjectOnGithub.
public static void shareProjectOnGithub(@NotNull final Project project, @Nullable final VirtualFile file) {
BasicAction.saveAll();
// get gitRepository
final GitRepository gitRepository = GithubUtil.getGitRepository(project, file);
final boolean gitDetected = gitRepository != null;
final VirtualFile root = gitDetected ? gitRepository.getRoot() : project.getBaseDir();
final GithubAuthDataHolder authHolder = GithubAuthDataHolder.createFromSettings();
// check for existing git repo
Set<String> existingRemotes = Collections.emptySet();
if (gitDetected) {
final String githubRemote = GithubUtil.findGithubRemoteUrl(gitRepository);
if (githubRemote != null) {
if (!checkExistingRemote(project, authHolder, githubRemote))
return;
}
existingRemotes = ContainerUtil.map2Set(gitRepository.getRemotes(), GitRemote::getName);
}
// get available GitHub repos with modal progress
final GithubInfo githubInfo = loadGithubInfoWithModal(authHolder, project);
if (githubInfo == null) {
return;
}
// Show dialog (window)
final GithubShareDialog shareDialog = new GithubShareDialog(project, githubInfo.getRepositoryNames(), existingRemotes, githubInfo.getUser().canCreatePrivateRepo());
DialogManager.show(shareDialog);
if (!shareDialog.isOK()) {
return;
}
final boolean isPrivate = shareDialog.isPrivate();
final String name = shareDialog.getRepositoryName();
final String description = shareDialog.getDescription();
final String remoteName = shareDialog.getRemoteName();
new Task.Backgroundable(project, "Sharing Project on GitHub...") {
@Override
public void run(@NotNull ProgressIndicator indicator) {
// create GitHub repo (network)
LOG.info("Creating GitHub repository");
indicator.setText("Creating GitHub repository...");
final String url = createGithubRepository(project, authHolder, indicator, name, description, isPrivate);
if (url == null) {
return;
}
LOG.info("Successfully created GitHub repository");
// creating empty git repo if git is not initialized
LOG.info("Binding local project with GitHub");
if (!gitDetected) {
LOG.info("No git detected, creating empty git repo");
indicator.setText("Creating empty git repo...");
if (!createEmptyGitRepository(project, root, indicator)) {
return;
}
}
GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(project);
final GitRepository repository = repositoryManager.getRepositoryForRoot(root);
if (repository == null) {
GithubNotifications.showError(project, "Failed to create GitHub Repository", "Can't find Git repository");
return;
}
final String remoteUrl = GithubUrlUtil.getCloneUrl(githubInfo.getUser().getLogin(), name);
//git remote add origin git@github.com:login/name.git
LOG.info("Adding GitHub as a remote host");
indicator.setText("Adding GitHub as a remote host...");
if (!GithubUtil.addGithubRemote(project, repository, remoteName, remoteUrl)) {
return;
}
// create sample commit for binding project
if (!performFirstCommitIfRequired(project, root, repository, indicator, name, url)) {
return;
}
//git push origin master
LOG.info("Pushing to github master");
indicator.setText("Pushing to github master...");
if (!pushCurrentBranch(project, repository, remoteName, remoteUrl, name, url)) {
return;
}
GithubNotifications.showInfoURL(project, "Successfully shared project on GitHub", name, url);
}
}.queue();
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class GithubOpenInBrowserAction method getDataFromHistory.
@Nullable
private static CommitData getDataFromHistory(AnActionEvent e) {
Project project = e.getData(CommonDataKeys.PROJECT);
FilePath filePath = e.getData(VcsDataKeys.FILE_PATH);
VcsFileRevision fileRevision = e.getData(VcsDataKeys.VCS_FILE_REVISION);
if (project == null || filePath == null || fileRevision == null)
return null;
if (!(fileRevision instanceof GitFileRevision))
return null;
GitRepository repository = GitUtil.getRepositoryManager(project).getRepositoryForFile(filePath);
if (repository == null || !GithubUtil.isRepositoryOnGitHub(repository))
return null;
return new CommitData(project, repository, fileRevision.getRevisionNumber().asString());
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class CloudGitDeploymentChecker method checkGitUrl.
public void checkGitUrl(final RemoteServer<SC> server, final DeploymentSource deploymentSource, final T settings) throws RuntimeConfigurationException {
if (!(deploymentSource instanceof ModuleDeploymentSource)) {
return;
}
ModuleDeploymentSource moduleSource = (ModuleDeploymentSource) deploymentSource;
Module module = moduleSource.getModule();
if (module == null) {
return;
}
File contentRootFile = deploymentSource.getFile();
if (contentRootFile == null) {
return;
}
final Project project = module.getProject();
VirtualFile contentRoot = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(contentRootFile);
if (contentRoot == null) {
return;
}
GitRepository repository = GitUtil.getRepositoryManager(project).getRepositoryForRoot(contentRoot);
if (repository == null) {
return;
}
String expectedName = settings.getDeploymentSourceName(deploymentSource);
List<String> appNames = myDetector.collectApplicationNames(repository);
if (appNames.isEmpty() || appNames.contains(expectedName)) {
return;
}
RuntimeConfigurationWarning warning = new RuntimeConfigurationWarning("Cloud Git URL found in repository, but it doesn't match the run configuration");
warning.setQuickFix(() -> {
CloudGitApplication application = new CloudConnectionTask<CloudGitApplication, SC, T, SR>(project, "Searching for application", server) {
@Override
protected CloudGitApplication run(SR serverRuntime) throws ServerRuntimeException {
CloudGitDeploymentRuntime deploymentRuntime = (CloudGitDeploymentRuntime) serverRuntime.createDeploymentRuntime(deploymentSource, settings, project);
return deploymentRuntime.findApplication4Repository();
}
}.performSync();
if (application == null) {
Messages.showErrorDialog(project, "No application matching repository URL(s) found in account", server.getName());
} else {
settings.setDefaultDeploymentName(false);
settings.setDeploymentName(application.getName());
}
});
throw warning;
}
use of git4idea.repo.GitRepository in project intellij-community by JetBrains.
the class CloudGitDeploymentRuntime method isRelevant.
private boolean isRelevant(ContentRevision contentRevision) throws ServerRuntimeException {
if (contentRevision == null) {
return false;
}
GitRepository repository = getRepository();
VirtualFile affectedFile = contentRevision.getFile().getVirtualFile();
return affectedFile != null && VfsUtilCore.isAncestor(repository.getRoot(), affectedFile, false);
}
Aggregations