Follow-up from "Refactor root sha access code"
<!--IssueSummary start-->
<details>
<summary>
Everyone can contribute. [Help move this issue forward](https://handbook.gitlab.com/handbook/marketing/developer-relations/contributor-success/community-contributors-workflows/#contributor-links) while earning points, leveling up and collecting rewards.
</summary>
- [Close this issue](https://contributors.gitlab.com/manage-issue?action=close&projectId=278964&issueIid=391966)
</details>
<!--IssueSummary end-->
The following discussion from !112289 should be addressed:
- [ ] @mhamda started a [discussion](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/112289#note_1283014052): (+1 comment)
### Problem
Method [`#root_ref_sha`](https://gitlab.com/gitlab-org/gitlab/blob/1897dbdfef270298e069a3f4d6e908afb1d11737/app/models/repository.rb#L963) is used in multiple places, but it is not safe to use. For example, it can raise an exception if repository is empty.
### Proposal
1. Verify commit existence and return `nil` instead of an exception.
2. Test and update, if necessary, all cases where the method is used. (if the code relies on the exception, then update it to handle `nil` value)
issue