Search in sources :

Example 66 with GitRepository

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GitRepository(git4idea.repo.GitRepository)

Example 67 with GitRepository

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) GithubAuthDataHolder(org.jetbrains.plugins.github.util.GithubAuthDataHolder) GitRepositoryManager(git4idea.repo.GitRepositoryManager) GitRepository(git4idea.repo.GitRepository) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) GithubShareDialog(org.jetbrains.plugins.github.ui.GithubShareDialog)

Example 68 with GitRepository

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());
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) Project(com.intellij.openapi.project.Project) GitRepository(git4idea.repo.GitRepository) GitFileRevision(git4idea.GitFileRevision) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) Nullable(org.jetbrains.annotations.Nullable)

Example 69 with GitRepository

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CloudGitApplication(com.intellij.remoteServer.agent.util.CloudGitApplication) Project(com.intellij.openapi.project.Project) GitRepository(git4idea.repo.GitRepository) ModuleDeploymentSource(com.intellij.remoteServer.configuration.deployment.ModuleDeploymentSource) RuntimeConfigurationWarning(com.intellij.execution.configurations.RuntimeConfigurationWarning) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 70 with GitRepository

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRepository(git4idea.repo.GitRepository)

Aggregations

GitRepository (git4idea.repo.GitRepository)123 VirtualFile (com.intellij.openapi.vfs.VirtualFile)46 NotNull (org.jetbrains.annotations.NotNull)33 Nullable (org.jetbrains.annotations.Nullable)19 Project (com.intellij.openapi.project.Project)18 GitCommandResult (git4idea.commands.GitCommandResult)14 GitRepositoryManager (git4idea.repo.GitRepositoryManager)12 VcsException (com.intellij.openapi.vcs.VcsException)11 AccessToken (com.intellij.openapi.application.AccessToken)9 File (java.io.File)8 Map (java.util.Map)8 GitRemote (git4idea.repo.GitRemote)7 FilePath (com.intellij.openapi.vcs.FilePath)6 Change (com.intellij.openapi.vcs.changes.Change)6 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 Task (com.intellij.openapi.progress.Task)5 ArrayList (java.util.ArrayList)5 ObjectUtils.assertNotNull (com.intellij.util.ObjectUtils.assertNotNull)4 MultiMap (com.intellij.util.containers.MultiMap)4 GitBranch (git4idea.GitBranch)4