Incorrect link-to-file target when browsing history for renamed files
<!--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=482490)
</details>
<!--IssueSummary end-->
<!---
Please read this!
Before opening a new issue, make sure to search for keywords in the issues
filtered by the "regression" or "type::bug" label:
- https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=regression
- https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=type::bug
and verify the issue you're about to submit isn't a duplicate.
--->
### Summary
When browsing the history of a file within the repository, a list of commits is provided that alter this file, together with a browse button that allows showing the file (and repository) state at the moment of that particular commit. This link will always contain the current filepath of the file, however if the file has been renamed at some point in its history, this causes the links before that commit to direct the user to a non-existing file, namely the new filename within an older repository state.
In such cases, one would expect the old path to be used, so that the correct file is shown. This would possibly go accompanied by a status banner notifying the user that this is an old file location which differs from the one in the current state of the repository.
### Steps to reproduce
1. Have/create a project with >= 1 commit
2. Move a file from path A to path B in commit C
3. Open history for file at path B
4. Click `Browse Directory` on any commit before commit C
### Example Project
<!-- If possible, please create an example project here on GitLab.com that exhibits the problematic
behavior, and link to it here in the bug report. If you are using an older version of GitLab, this
will also determine whether the bug is fixed in a more recent version. -->
https://gitlab.com/jnoordsij/git-history-link-bug-mwe/-/commits/main/bar?ref_type=heads
### What is the current *bug* behavior?
When clicking the `Browse Directory` button on commit foo, one is linked to https://gitlab.com/jnoordsij/git-history-link-bug-mwe/-/tree/9d644ff34186d98f53638e39e99cf65e2b024a15/bar, which does not exist and hence redirects to https://gitlab.com/jnoordsij/git-history-link-bug-mwe/-/tree/9d644ff34186d98f53638e39e99cf65e2b024a15 with status message `"bar" did not exist on "9d644ff34186d98f53638e39e99cf65e2b024a15"`.
### What is the expected *correct* behavior?
When clicking the `Browse Directory` button on commit foo, one is linked to https://gitlab.com/jnoordsij/git-history-link-bug-mwe/-/tree/9d644ff34186d98f53638e39e99cf65e2b024a15/foo, which is the previous location of `bar`.
### Relevant logs and/or screenshots
<!-- Paste any relevant logs - please use code blocks (```) to format console output, logs, and code
as it's tough to read otherwise. -->
### Output of checks
<!-- If you are reporting a bug on GitLab.com, uncomment below -->
This bug happens on GitLab.com
#### Results of GitLab environment info
<!-- Input any relevant GitLab environment information if needed. -->
<details>
<summary>Expand for output related to GitLab environment info</summary>
<pre>
(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)
(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
</pre>
</details>
#### Results of GitLab application Check
<!-- Input any relevant GitLab application check information if needed. -->
<details>
<summary>Expand for output related to the GitLab application check</summary>
<pre>
(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:check SANITIZE=true`)
(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true`)
(we will only investigate if the tests are passing)
</pre>
</details>
### Possible fixes
<!-- If you can, link to the line of code that might be responsible for the problem. -->
issue