private static @Nullable AnAction createBranchGroup(@NotNull Project project,
                                                      @NotNull VcsRef ref,
                                                      @NotNull GitRepository repository,
                                                      @NotNull List<? extends GitRepository> allRepositories,
                                                      @NotNull Set<GitBranch> commonBranches,
                                                      @NotNull GitVcsSettings settings,
                                                      boolean showBranchesPopup) {
    // ref.getName() for GitRefManager.REMOTE_BRANCH is GitRemoteBranch.getNameForLocalOperations
    GitBranch branch = ref.getType() == GitRefManager.LOCAL_BRANCH
                       ? new GitLocalBranch(ref.getName())
                       : GitUtil.parseRemoteBranch(ref.getName(), repository.getRemotes());

    List<AnAction> actions = new ArrayList<>(3);

    boolean isSyncBranch = settings.getSyncSetting() != DvcsSyncSettings.Value.DONT_SYNC &&
                           allRepositories.size() > 1 &&
                           commonBranches.contains(branch);
    if (isSyncBranch) {
      ActionGroup allReposActions = createBranchActions(project, allRepositories, branch, repository);
      if (allReposActions != null) {
        allReposActions.getTemplatePresentation().setText(GitBundle.message("in.branches.all.repositories"));
        allReposActions.setPopup(true);
        actions.add(allReposActions);
        actions.add(Separator.getInstance());
      }
    }

    ActionGroup singleRepoActions = createBranchActions(project, Collections.singletonList(repository), branch, repository);
    if (singleRepoActions == null) return null;
    singleRepoActions.setPopup(false);
    actions.add(singleRepoActions);

    String text = showBranchesPopup ? ref.getName() : GitBundle.message("branches.branch.0", ref.getName());
    ActionGroup group = new DefaultActionGroup(actions);
    group.getTemplatePresentation().setText(text, false);
    group.setPopup(true);
    return group;
  }
private static @Nullable AnAction createBranchGroup(@NotNull Project project,
                                                      @NotNull VcsRef ref,
                                                      @NotNull GitRepository repository,
                                                      @NotNull List<? extends GitRepository> allRepositories,
                                                      @NotNull Set<GitBranch> commonBranches,
                                                      @NotNull GitVcsSettings settings,
                                                      boolean showBranchesPopup)