Commit 54de35ad authored by Stan Hu's avatar Stan Hu
Browse files

Gracefully handle case when repository's root ref does not exist

This was failing regularly with an Error 500 when the API branches endpoint
was used.

Closes #40615
parent 8198461f5b13
title: "Gracefully handle case when repository's root ref does not exist"
type: fixed
......@@ -1253,7 +1253,11 @@ def branches_filter(filter: nil, sort_by: nil)
# Gitaly migration:
def git_merged_branch_names(branch_names = [])
root_sha = find_branch(root_ref).target
return [] unless root_ref
root_sha = find_branch(root_ref)&.target
return [] unless root_sha
git_arguments =
%W[branch --merged #{root_sha}
......@@ -1210,6 +1210,16 @@ def commit_files(commit)
context 'when no root ref is available' do
it 'returns empty list' do
project = create(:project, :empty_repo)
names = project.repository.merged_branch_names(%w[feature])
expect(names).to be_empty
context 'when no branch names are specified' do
before do
repository.create_branch('identical', 'master')
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