Search in sources :

Example 1 with GitBranch

use of git4idea.GitBranch in project intellij-community by JetBrains.

the class DeepComparator method getRepositories.

@NotNull
private Map<GitRepository, GitBranch> getRepositories(@NotNull Map<VirtualFile, VcsLogProvider> providers, @NotNull String branchToCompare) {
    Map<GitRepository, GitBranch> repos = ContainerUtil.newHashMap();
    for (VirtualFile root : providers.keySet()) {
        GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
        if (repository == null || repository.getCurrentBranch() == null || repository.getBranches().findBranchByName(branchToCompare) == null) {
            continue;
        }
        repos.put(repository, repository.getCurrentBranch());
    }
    return repos;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRepository(git4idea.repo.GitRepository) GitBranch(git4idea.GitBranch) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GitBranch

use of git4idea.GitBranch 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 3 with GitBranch

use of git4idea.GitBranch in project intellij-community by JetBrains.

the class GitRebaseUpdater method getRemoteBranchToMerge.

@NotNull
private String getRemoteBranchToMerge() {
    GitBranchPair gitBranchPair = myTrackedBranches.get(myRoot);
    GitBranch dest = gitBranchPair.getDest();
    LOG.assertTrue(dest != null, String.format("Destination branch is null for source branch %s in %s", gitBranchPair.getBranch().getName(), myRoot));
    return dest.getName();
}
Also used : GitBranchPair(git4idea.branch.GitBranchPair) GitBranch(git4idea.GitBranch) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with GitBranch

use of git4idea.GitBranch 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 5 with GitBranch

use of git4idea.GitBranch in project intellij-community by JetBrains.

the class GitCompareWithBranchAction method getBranchNamesExceptCurrent.

@NotNull
@Override
protected List<String> getBranchNamesExceptCurrent(@NotNull GitRepository repository) {
    List<GitBranch> localBranches = new ArrayList<>(repository.getBranches().getLocalBranches());
    Collections.sort(localBranches);
    List<GitBranch> remoteBranches = new ArrayList<>(repository.getBranches().getRemoteBranches());
    Collections.sort(remoteBranches);
    if (repository.isOnBranch()) {
        localBranches.remove(repository.getCurrentBranch());
    }
    List<String> branchNames = ContainerUtil.newArrayList();
    for (GitBranch branch : localBranches) {
        branchNames.add(branch.getName());
    }
    for (GitBranch branch : remoteBranches) {
        branchNames.add(branch.getName());
    }
    return branchNames;
}
Also used : ArrayList(java.util.ArrayList) GitBranch(git4idea.GitBranch) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GitBranch (git4idea.GitBranch)7 GitRepository (git4idea.repo.GitRepository)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 NotNull (org.jetbrains.annotations.NotNull)3 GitBranchPair (git4idea.branch.GitBranchPair)1 GitBranchesCollection (git4idea.branch.GitBranchesCollection)1 GitSimpleHandler (git4idea.commands.GitSimpleHandler)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1