Search in sources :

Example 41 with GitRepository

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

the class GitMergeProvider method resolveMergeHead.

@Nullable
private GitRevisionNumber resolveMergeHead(@NotNull VirtualFile root) {
    try {
        return GitRevisionNumber.resolve(myProject, root, MERGE_HEAD);
    } catch (VcsException e) {
        // this may be not a bug, just cherry-pick
        LOG.info("Couldn't resolve the MERGE_HEAD in " + root + ": " + e.getMessage());
    }
    try {
        return GitRevisionNumber.resolve(myProject, root, CHERRY_PICK_HEAD);
    } catch (VcsException e) {
        LOG.info("Couldn't resolve the CHERRY_PICK_HEAD in " + root + ": " + e.getMessage());
    }
    GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(root);
    assert repository != null;
    File rebaseApply = repository.getRepositoryFiles().getRebaseApplyDir();
    GitRevisionNumber rebaseRevision = readRevisionFromFile(new File(rebaseApply, "original-commit"));
    if (rebaseRevision != null)
        return rebaseRevision;
    File rebaseMerge = repository.getRepositoryFiles().getRebaseMergeDir();
    GitRevisionNumber mergeRevision = readRevisionFromFile(new File(rebaseMerge, "stopped-sha"));
    if (mergeRevision != null)
        return mergeRevision;
    return null;
}
Also used : GitRepository(git4idea.repo.GitRepository) GitRevisionNumber(git4idea.GitRevisionNumber) VcsException(com.intellij.openapi.vcs.VcsException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 42 with GitRepository

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

the class GitPullDialog method updateBranches.

private void updateBranches() {
    final String selectedRemote = getRemote();
    myBranchChooser.removeAllElements();
    if (selectedRemote == null) {
        return;
    }
    GitRepository repository = getRepository();
    if (repository == null) {
        return;
    }
    GitBranchTrackInfo trackInfo = GitUtil.getTrackInfoForCurrentBranch(repository);
    GitRemoteBranch currentRemoteBranch = trackInfo == null ? null : trackInfo.getRemoteBranch();
    List<GitRemoteBranch> remoteBranches = new ArrayList<>(repository.getBranches().getRemoteBranches());
    Collections.sort(remoteBranches);
    myBranchChooser.setElements(ContainerUtil.mapNotNull(remoteBranches, new Function<GitRemoteBranch, String>() {

        @Override
        public String fun(GitRemoteBranch branch) {
            return branch.getRemote().getName().equals(selectedRemote) ? branch.getNameForLocalOperations() : null;
        }
    }), false);
    if (currentRemoteBranch != null && currentRemoteBranch.getRemote().getName().equals(selectedRemote)) {
        myBranchChooser.setElementMarked(currentRemoteBranch.getNameForLocalOperations(), true);
    }
    validateDialog();
}
Also used : GitRepository(git4idea.repo.GitRepository) Function(com.intellij.util.Function) ArrayList(java.util.ArrayList) GitBranchTrackInfo(git4idea.repo.GitBranchTrackInfo) GitRemoteBranch(git4idea.GitRemoteBranch)

Example 43 with GitRepository

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

the class GitPullDialog method getRepository.

@Nullable
private GitRepository getRepository() {
    VirtualFile root = gitRoot();
    GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
    if (repository == null) {
        LOG.error("Repository is null for " + root);
        return null;
    }
    return repository;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRepository(git4idea.repo.GitRepository) Nullable(org.jetbrains.annotations.Nullable)

Example 44 with GitRepository

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

the class GitPullDialog method updateRemotes.

private void updateRemotes() {
    GitRepository repository = getRepository();
    if (repository == null) {
        return;
    }
    GitRemote currentRemote = getCurrentOrDefaultRemote(repository);
    myRemote.setRenderer(getGitRemoteListCellRenderer(currentRemote != null ? currentRemote.getName() : null));
    myRemote.removeAllItems();
    for (GitRemote remote : repository.getRemotes()) {
        myRemote.addItem(remote);
    }
    myRemote.setSelectedItem(currentRemote);
}
Also used : GitRemote(git4idea.repo.GitRemote) GitRepository(git4idea.repo.GitRepository)

Example 45 with GitRepository

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

the class GroupedPushResult method group.

@NotNull
static GroupedPushResult group(@NotNull Map<GitRepository, GitPushRepoResult> results) {
    Map<GitRepository, GitPushRepoResult> successful = ContainerUtil.newHashMap();
    Map<GitRepository, GitPushRepoResult> rejected = ContainerUtil.newHashMap();
    Map<GitRepository, GitPushRepoResult> customRejected = ContainerUtil.newHashMap();
    Map<GitRepository, GitPushRepoResult> errors = ContainerUtil.newHashMap();
    for (Map.Entry<GitRepository, GitPushRepoResult> entry : results.entrySet()) {
        GitRepository repository = entry.getKey();
        GitPushRepoResult result = entry.getValue();
        if (result.getType() == GitPushRepoResult.Type.REJECTED_NO_FF) {
            rejected.put(repository, result);
        } else if (result.getType() == GitPushRepoResult.Type.ERROR) {
            errors.put(repository, result);
        } else if (result.getType() == GitPushRepoResult.Type.REJECTED_OTHER) {
            customRejected.put(repository, result);
        } else {
            successful.put(repository, result);
        }
    }
    return new GroupedPushResult(successful, errors, rejected, customRejected);
}
Also used : GitRepository(git4idea.repo.GitRepository) Map(java.util.Map) 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