Commit 3e78b5ae authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'sh-fix-root-ref-repository' into 'master'

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

Closes #40615

See merge request gitlab-org/gitlab-ce!15678
parents f999fa4c 66127221
---
title: "Gracefully handle case when repository's root ref does not exist"
merge_request:
author:
type: fixed
...@@ -1253,7 +1253,11 @@ module Gitlab ...@@ -1253,7 +1253,11 @@ module Gitlab
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/695 # Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/695
def git_merged_branch_names(branch_names = []) 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 = git_arguments =
%W[branch --merged #{root_sha} %W[branch --merged #{root_sha}
......
...@@ -1210,6 +1210,16 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -1210,6 +1210,16 @@ describe Gitlab::Git::Repository, seed_helper: true do
end end
end end
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
end
end
context 'when no branch names are specified' do context 'when no branch names are specified' do
before do before do
repository.create_branch('identical', 'master') 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