Search in sources :

Example 86 with GitRepository

use of git4idea.repo.GitRepository in project intellij-community by JetBrains.

the class GitRejectedPushUpdateDialog method makeDescription.

private String makeDescription() {
    if (GitUtil.justOneGitRepository(myProject)) {
        assert !myRepositories.isEmpty() : "repositories are empty";
        GitRepository repository = myRepositories.iterator().next();
        GitBranch currentBranch = getCurrentBranch(repository);
        return DESCRIPTION_START + code(currentBranch.getName()) + " was rejected. <br/>" + descriptionEnding();
    } else if (myRepositories.size() == 1) {
        // there are more than 1 repositories in the project, but only one was rejected
        GitRepository repository = myRepositories.iterator().next();
        GitBranch currentBranch = getCurrentBranch(repository);
        return DESCRIPTION_START + code(currentBranch.getName()) + " in repository <br/>" + code(repository.getPresentableUrl()) + " was rejected. <br/>" + descriptionEnding();
    } else {
        // several repositories rejected the push
        Map<GitRepository, GitBranch> currentBranches = getCurrentBranches();
        if (allBranchesHaveTheSameName(currentBranches)) {
            String branchName = currentBranches.values().iterator().next().getName();
            StringBuilder sb = new StringBuilder(DESCRIPTION_START + code(branchName) + " was rejected in repositories <br/>");
            for (GitRepository repository : DvcsUtil.sortRepositories(currentBranches.keySet())) {
                sb.append(HTML_IDENT).append(code(repository.getPresentableUrl())).append("<br/>");
            }
            sb.append(descriptionEnding());
            return sb.toString();
        } else {
            StringBuilder sb = new StringBuilder("<html>Push of current branch was rejected: <br/>");
            for (Map.Entry<GitRepository, GitBranch> entry : currentBranches.entrySet()) {
                GitRepository repository = entry.getKey();
                GitBranch currentBranch = entry.getValue();
                sb.append(HTML_IDENT + code(currentBranch.getName()) + " in " + code(repository.getPresentableUrl()) + "<br/>");
            }
            sb.append(descriptionEnding());
            return sb.toString();
        }
    }
}
Also used : GitRepository(git4idea.repo.GitRepository) GitBranch(git4idea.GitBranch) HashMap(java.util.HashMap) Map(java.util.Map)

Example 87 with GitRepository

use of git4idea.repo.GitRepository in project intellij-community by JetBrains.

the class GitBranchesAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE);
    GitRepository repository = file == null ? GitBranchUtil.getCurrentRepository(project) : GitBranchUtil.getRepositoryOrGuess(project, file);
    if (repository != null) {
        GitBranchPopup.getInstance(project, repository).asListPopup().showCenteredInCurrentWindow(project);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GitRepository(git4idea.repo.GitRepository)

Example 88 with GitRepository

use of git4idea.repo.GitRepository in project intellij-community by JetBrains.

the class CloudGitProjectStructureDetector method detectApplicationRoot.

private static void detectApplicationRoot(@NotNull File dir, @NotNull List<DetectedProjectRoot> result) {
    VirtualFile repositoryRoot = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(dir);
    if (repositoryRoot == null) {
        return;
    }
    if (GitUtil.findGitDir(repositoryRoot) == null) {
        return;
    }
    Project project = ProjectManager.getInstance().getDefaultProject();
    GitRepository repository = GitRepositoryImpl.getInstance(repositoryRoot, project, false);
    for (CloudGitDeploymentDetector deploymentDetector : CloudGitDeploymentDetector.EP_NAME.getExtensions()) {
        String applicationName = deploymentDetector.getFirstApplicationName(repository);
        if (applicationName != null) {
            result.add(new CloudGitProjectRoot(deploymentDetector, dir, repositoryRoot, applicationName));
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GitRepository(git4idea.repo.GitRepository) CloudGitDeploymentDetector(com.intellij.remoteServer.util.CloudGitDeploymentDetector)

Example 89 with GitRepository

use of git4idea.repo.GitRepository in project intellij-community by JetBrains.

the class GitRepositoryForAnnotationsListener method createListener.

private GitRepositoryChangeListener createListener() {
    return new GitRepositoryChangeListener() {

        @Override
        public void repositoryChanged(@NotNull GitRepository repository) {
            final VcsAnnotationRefresher refresher = myProject.getMessageBus().syncPublisher(VcsAnnotationRefresher.LOCAL_CHANGES_CHANGED);
            refresher.dirtyUnder(repository.getRoot());
        }
    };
}
Also used : GitRepository(git4idea.repo.GitRepository) GitRepositoryChangeListener(git4idea.repo.GitRepositoryChangeListener) VcsAnnotationRefresher(com.intellij.openapi.vcs.changes.VcsAnnotationRefresher) NotNull(org.jetbrains.annotations.NotNull)

Example 90 with GitRepository

use of git4idea.repo.GitRepository in project intellij-community by JetBrains.

the class GitBranchUtil method getCurrentBranchOrRev.

@NotNull
static String getCurrentBranchOrRev(@NotNull Collection<GitRepository> repositories) {
    if (repositories.size() > 1) {
        GitMultiRootBranchConfig multiRootBranchConfig = new GitMultiRootBranchConfig(repositories);
        String currentBranch = multiRootBranchConfig.getCurrentBranch();
        LOG.assertTrue(currentBranch != null, "Repositories have unexpectedly diverged. " + multiRootBranchConfig);
        return currentBranch;
    } else {
        assert !repositories.isEmpty() : "No repositories passed to GitBranchOperationsProcessor.";
        GitRepository repository = repositories.iterator().next();
        return getBranchNameOrRev(repository);
    }
}
Also used : GitRepository(git4idea.repo.GitRepository) GitMultiRootBranchConfig(git4idea.ui.branch.GitMultiRootBranchConfig) ObjectUtils.assertNotNull(com.intellij.util.ObjectUtils.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

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