Commit 8991ba89 authored by Alishan Ladhani's avatar Alishan Ladhani

Respect `ref` when searching for commits

Fixes a bug where the branch is always assumed to be
master, even when the user specifies a branch they
want to search
parent d09642e1
---
title: Fix incorrect commit search results returned when searching with ref
merge_request: 33216
author:
type: fixed
...@@ -159,7 +159,7 @@ module Gitlab ...@@ -159,7 +159,7 @@ module Gitlab
end end
def find_commits_by_message(query, limit:) def find_commits_by_message(query, limit:)
project.repository.find_commits_by_message(query, nil, nil, limit) project.repository.find_commits_by_message(query, repository_project_ref, nil, limit)
end end
def find_commit_by_sha(query) def find_commit_by_sha(query)
......
...@@ -530,6 +530,18 @@ describe Gitlab::ProjectSearchResults do ...@@ -530,6 +530,18 @@ describe Gitlab::ProjectSearchResults do
expect(commits).to be_empty expect(commits).to be_empty
end end
context 'when repository_ref is provided' do
let(:message) { 'Feature added' }
let(:repository_ref) { +'feature' }
it 'searches in the specified ref' do
commits = described_class.new(user, project, message, repository_ref).objects('commits')
# This commit is unique to the feature branch
expect(commits).to contain_exactly(project.repository.commit('0b4bc9a49b562e85de7cc9e834518ea6828729b9'))
end
end
it_behaves_like 'access restricted commits' do it_behaves_like 'access restricted commits' do
let(:search_phrase) { message } let(:search_phrase) { message }
let(:commit) { project.repository.commit('59e29889be61e6e0e5e223bfa9ac2721d31605b8') } let(:commit) { project.repository.commit('59e29889be61e6e0e5e223bfa9ac2721d31605b8') }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment