Skip to content

Tree path lost when switching revisions in Commits view

Summary

When changing revisions in the Commits view of a specific path, the view redirects to the root directory of the new revision, losing the selected path.

Steps to reproduce

  1. Browse to a file in a repo. For example: gitlab/-/blob/master/README.md?ref_type=heads.
  2. Click on the History button to load its corresponding commit view (gitlab/-/commits/master/README.md?ref_type=heads).
  3. Use the Git revision selector to switch to a different branch or tag.

What is the current bug behavior?

The selected branch/tag's commit history is shown for the root directory of the repo; not for the path that was selected before switching revisions.

What is the expected correct behavior?

The page loaded should show the commit history of the selected path in the new ref if it exists on it, like the blob view currently does.

For example, selecting v16.7.6-ee loads

but should instead show

Possible fixes

  • Make initCommitsRefSwitcher() pass the selected path when changing to the URL of the newly-selected Git revision. And,
  • in order to make the commits view consistent with the blob view, adjust CommitsController so that if a path does not exist on a ref it shows a "$file did not exist on $ref" error message and redirects to the root directory of the repo instead.
Edited by 🤖 GitLab Bot 🤖