Commit dbf97574 authored by Douwe Maan's avatar Douwe Maan

Merge branch '39887-move-identical-check-to-merged-branches' into 'master'

Move identical merged branch check to merged_branch_names

Closes #39887

See merge request gitlab-org/gitlab-ce!15464
parents deda88f9 d6fcdec5
......@@ -909,19 +909,13 @@ class Repository
end
end
def merged_to_root_ref?(branch_or_name, pre_loaded_merged_branches = nil)
def merged_to_root_ref?(branch_or_name)
branch = Gitlab::Git::Branch.find(self, branch_or_name)
if branch
@root_ref_sha ||= commit(root_ref).sha
same_head = branch.target == @root_ref_sha
merged =
if pre_loaded_merged_branches
pre_loaded_merged_branches.include?(branch.name)
else
ancestor?(branch.target, @root_ref_sha)
end
merged = ancestor?(branch.target, @root_ref_sha)
!same_head && merged
else
nil
......
......@@ -38,7 +38,7 @@
- if @branches.any?
%ul.content-list.all-branches
- @branches.each do |branch|
= render "projects/branches/branch", branch: branch, merged: @repository.merged_to_root_ref?(branch, @merged_branch_names)
= render "projects/branches/branch", branch: branch, merged: @merged_branch_names.include?(branch.name)
= paginate @branches, theme: 'gitlab'
- else
.nothing-here-block
......
......@@ -242,7 +242,11 @@ module API
end
expose :merged do |repo_branch, options|
options[:project].repository.merged_to_root_ref?(repo_branch, options[:merged_branch_names])
if options[:merged_branch_names]
options[:merged_branch_names].include?(repo_branch.name)
else
options[:project].repository.merged_to_root_ref?(repo_branch)
end
end
expose :protected do |repo_branch, options|
......
......@@ -1243,11 +1243,21 @@ module Gitlab
sort_branches(branches, sort_by)
end
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/695
def git_merged_branch_names(branch_names = [])
lines = run_git(['branch', '--merged', root_ref] + branch_names)
.first.lines
root_sha = find_branch(root_ref).target
lines.map(&:strip)
git_arguments =
%W[branch --merged #{root_sha}
--format=%(refname:short)\ %(objectname)] + branch_names
lines = run_git(git_arguments).first.lines
lines.each_with_object([]) do |line, branches|
name, sha = line.strip.split(' ', 2)
branches << name if sha != root_sha
end
end
def log_using_shell?(options)
......
......@@ -14,6 +14,7 @@ fi
retry gem install knapsack
cp config/gitlab.yml.example config/gitlab.yml
sed -i 's/bin_path: \/usr\/bin\/git/bin_path: \/usr\/local\/bin\/git/' config/gitlab.yml
# Determine the database by looking at the job name.
# For example, we'll get pg if the job is `rspec-pg 19 20`
......
......@@ -1211,12 +1211,21 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
context 'when no branch names are specified' do
it 'returns all merged branch names' do
before do
repository.create_branch('identical', 'master')
end
after do
ensure_seeds
end
it 'returns all merged branch names except for identical one' do
names = repository.merged_branch_names
expect(names).to include('merge-test')
expect(names).to include('fix-mode')
expect(names).not_to include('feature')
expect(names).not_to include('identical')
end
end
end
......
......@@ -299,24 +299,6 @@ describe Repository do
it { is_expected.to be_falsey }
end
context 'when pre-loaded merged branches are provided' do
using RSpec::Parameterized::TableSyntax
where(:branch, :pre_loaded, :expected) do
'not-merged-branch' | ['branch-merged'] | false
'branch-merged' | ['not-merged-branch'] | false
'branch-merged' | ['branch-merged'] | true
'not-merged-branch' | ['not-merged-branch'] | false
'master' | ['master'] | false
end
with_them do
subject { repository.merged_to_root_ref?(branch, pre_loaded) }
it { is_expected.to eq(expected) }
end
end
end
describe '#can_be_merged?' do
......
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