Search from a commit detail does not use commit SHA as repository_ref

Summary

The search in navbar adapts to current context. When browsing through the files of a specific branch, or viewing a file in a specific version, the current version is used as repository_ref in the search. Yet, when viewing a commit page, the search bar searches only the master branch.

Steps to reproduce

  • Create a new branch
  • Commit a new file with a word that appears nowhere else in your codebase
  • Go to the detail page of your commit, enter the word you added in the search bar and hit search => no result
  • Go to the Files view, switch to the new branch, enter the word you added in the search bar and hit search => the file is found

Example Project

ykweyer-test-group/test-search@5eaa9064

=> Looking for perspiciatis doesn't return any result. But going to the files view and searching perspiciatis works

What is the current bug behavior?

The generated Search URL has an empty repository_ref: https://gitlab.com/search?utf8=%E2%9C%93&search=perspiciatis&group_id=&project_id=14219606&search_code=true&repository_ref=&nav_source=navbar

What is the expected correct behavior?

When visiting a commit detail page, repository_ref should be set to the commits sha, similar to when a single file is being viewed: https://gitlab.com/search?utf8=%E2%9C%93&search=perspiciatis&group_id=&project_id=14219606&search_code=true&repository_ref=5eaa9064b7cdc2a8a231f911f8f4f59167d5e38c&nav_source=navbar

Output of checks

This bug happens on GitLab.com

Edited by Yann Weyer