Skip to content

Fix for #18066, Users can change branches and remain on same file history.

What does this MR do?

Currently, while browsing the commit history of a specific file, if a user changes the branch, the user will be redirected to the commit history of the entire repository for the selected branch.

This MR corrects this, the user will remain on the commit history of the file even while changing branches.

Screenshots

Before After
cannot_change_branches can_change_branches

Details

The ref switcher needs to be provided the :path option and value in order to pass along the path of the file being viewed.

IMPORTANT: New Behavior

While users can now stay on the same file history while switching branches, the dropdown menu for branches does not filter branches based on the selected file. This means that if a user selects a branch where the file does not exist, the user will be presented with a 404 page.

Please note that this is the same behavior as seen in the Files section (ie: my_project/blob/master/foo.txt). If a user is viewing the contents of a file and switches to a branch where that files does not exist, the user is presented with a 404 page. Because I believe these changes make the behavior more consistent between the Files and Commits sections, I have reopened this merge request after previously closing it. I do intend on submitting feature proposals to more gracefully handle this issue, I think the user should be redirected to the root directory of the project rather than be presented with a 404 page.

Does this MR meet the acceptance criteria?

Conformity

Closes #18066 (closed)

Edited by Jesse Hall

Merge request reports

Loading