public static @Nls @NotNull String getDisplayableBranchText(@NotNull GitRepository repository,
                                                              @NotNull Function<@NotNull @NlsSafe String, @NotNull @NlsSafe String> branchNameTruncator) {
    GitRepository.State state = repository.getState();
    if (state == Repository.State.DETACHED) {
      String detachedStatePresentableText = getDetachedStatePresentableText(repository, branchNameTruncator);
      return detachedStatePresentableText != null ? detachedStatePresentableText : "";
    }

    GitBranch branch = repository.getCurrentBranch();
    String branchName = (branch == null ? "" : branchNameTruncator.apply(branch.getName()));

    if (state == GitRepository.State.MERGING) {
      return GitBundle.message("git.status.bar.widget.text.merge", branchName);
    }
    else if (state == GitRepository.State.REBASING) {
      return GitBundle.message("git.status.bar.widget.text.rebase", branchName);
    }
    else if (state == GitRepository.State.GRAFTING) {
      return GitBundle.message("git.status.bar.widget.text.cherry.pick", branchName);
    }
    else if (state == GitRepository.State.REVERTING) {
      return GitBundle.message("git.status.bar.widget.text.revert", branchName);
    }
    else {
      return branchName;
    }
  }
public static @Nls @NotNull String getDisplayableBranchText(@NotNull GitRepository repository,
                                                              @NotNull Function<@NotNull @NlsSafe String, @NotNull @NlsSafe String> branchNameTruncator)