Search in sources :

Example 61 with GitRepository

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

the class GitFileUtils method updateUntrackedFilesHolderOnFileRemove.

private static void updateUntrackedFilesHolderOnFileRemove(@NotNull Project project, @NotNull VirtualFile root, @NotNull Collection<VirtualFile> removedFiles) {
    GitRepository repository = GitUtil.getRepositoryManager(project).getRepositoryForRoot(root);
    if (repository == null) {
        LOG.error("Repository not found for root " + root.getPresentableUrl());
        return;
    }
    repository.getUntrackedFilesHolder().add(removedFiles);
}
Also used : GitRepository(git4idea.repo.GitRepository)

Example 62 with GitRepository

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

the class GithubCreatePullRequestAction 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 63 with GitRepository

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

the class GitNewBranchNameValidator method conflictsWithLocalOrRemote.

private boolean conflictsWithLocalOrRemote(@NotNull String inputString, boolean local, @NotNull String message) {
    int conflictsWithCurrentName = 0;
    for (GitRepository repository : myRepositories) {
        if (inputString.equals(repository.getCurrentBranchName())) {
            conflictsWithCurrentName++;
        } else {
            GitBranchesCollection branchesCollection = repository.getBranches();
            Collection<? extends GitBranch> branches = local ? branchesCollection.getLocalBranches() : branchesCollection.getRemoteBranches();
            for (GitBranch branch : branches) {
                if (branch.getName().equals(inputString)) {
                    myErrorText = "Branch name " + inputString + message;
                    if (myRepositories.size() > 1 && !allReposHaveBranch(inputString, local)) {
                        myErrorText += " in repository " + repository.getPresentableUrl();
                    }
                    return true;
                }
            }
        }
    }
    if (conflictsWithCurrentName == myRepositories.size()) {
        myErrorText = "You are already on branch " + inputString;
        return true;
    }
    return false;
}
Also used : GitRepository(git4idea.repo.GitRepository) GitBranchesCollection(git4idea.branch.GitBranchesCollection) GitBranch(git4idea.GitBranch)

Example 64 with GitRepository

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

the class GitNewBranchNameValidator method allReposHaveBranch.

private boolean allReposHaveBranch(String inputString, boolean local) {
    for (GitRepository repository : myRepositories) {
        GitBranchesCollection branchesCollection = repository.getBranches();
        Collection<? extends GitBranch> branches = local ? branchesCollection.getLocalBranches() : branchesCollection.getRemoteBranches();
        if (!GitBranchUtil.convertBranchesToNames(branches).contains(inputString)) {
            return false;
        }
    }
    return true;
}
Also used : GitRepository(git4idea.repo.GitRepository) GitBranchesCollection(git4idea.branch.GitBranchesCollection)

Example 65 with GitRepository

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

the class GithubOpenInBrowserAction method getDataFromVirtualFile.

@Nullable
private static CommitData getDataFromVirtualFile(AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    VirtualFile virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE);
    if (project == null || virtualFile == null)
        return null;
    GitRepository gitRepository = GitUtil.getRepositoryManager(project).getRepositoryForFile(virtualFile);
    if (gitRepository == null || !GithubUtil.isRepositoryOnGitHub(gitRepository))
        return null;
    ChangeListManager changeListManager = ChangeListManager.getInstance(project);
    if (changeListManager.isUnversioned(virtualFile))
        return new CommitData(project, gitRepository);
    Change change = changeListManager.getChange(virtualFile);
    if (change != null && change.getType() == Change.Type.NEW)
        return new CommitData(project, gitRepository);
    return new CommitData(project, gitRepository, virtualFile);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GitRepository(git4idea.repo.GitRepository) Change(com.intellij.openapi.vcs.changes.Change) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) Nullable(org.jetbrains.annotations.Nullable)

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