Guard against unresolvable root ref in DivergingCommitCountsService

What does this MR do and why?

Fixes a 500 error from Projects::BranchesController#diverging_commit_counts

NoMethodError: undefined method `id' for nil
  app/services/branches/diverging_commit_counts_service.rb:11:in `call'

When a repository's root ref (HEAD) doesn't resolve to a commit, raw_repository.commit(repository.root_ref) returns nil and every diverging counts request 500s. This is reachable via valid git states (unborn HEAD on an empty/renamed default branch, or HEAD pointing at a deleted branch), so a deterministic 500 mischaracterises a representable repository state as a server error.

How to set up and validate locally

  1. Point a test repo's HEAD at a non-existent branch (git symbolic-ref HEAD refs/heads/gone on the Gitaly-side repo).
  2. Load the Branches page. Before: 500 + "Error fetching diverging counts" alert. After: 200 with {}, page renders cleanly, one UnresolvableRootRefError tracked.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Gavin Hinfey

Merge request reports

Loading
Loading