From 7df1cb528e5d977f5f18b1c82433b3c76220d6db Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Sat, 18 Nov 2017 02:13:45 +0800 Subject: Move identical merged branch check to merged_branch_names --- app/models/repository.rb | 10 ++-------- app/views/projects/branches/index.html.haml | 2 +- lib/api/entities.rb | 6 +++++- lib/gitlab/git/repository.rb | 16 +++++++++++++--- spec/lib/gitlab/git/repository_spec.rb | 7 ++++++- spec/models/repository_spec.rb | 18 ------------------ 6 files changed, 27 insertions(+), 32 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index 2bf21cbdcc4..d4ffd7bfc07 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -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 diff --git a/app/views/projects/branches/index.html.haml b/app/views/projects/branches/index.html.haml index aade310236e..fb770764364 100644 --- a/app/views/projects/branches/index.html.haml +++ b/app/views/projects/branches/index.html.haml @@ -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 diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 16ae99b5c6c..acfd4a1ef4d 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -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| diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index dcca20c75ef..ff408c0c4dd 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -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) diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index f0da77c61bb..725e851aa9d 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -1211,12 +1211,17 @@ 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 + + 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 diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index e9e6abb0d5f..27f0a99b2fa 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -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 -- cgit v1.2.1 From 5951320075759ae8ec1f73b37ced10fc484f428f Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 22 Nov 2017 15:02:37 +0800 Subject: Make sure repository is restored --- spec/lib/gitlab/git/repository_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 725e851aa9d..9da33b94c5e 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -1215,6 +1215,10 @@ describe Gitlab::Git::Repository, seed_helper: true 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 -- cgit v1.2.1 From d6fcdec52f795f59526c5908349e918d499da2b3 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 22 Nov 2017 23:41:24 +0800 Subject: Make sure we're using git installed in gitlab-build-images --- scripts/prepare_build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/prepare_build.sh b/scripts/prepare_build.sh index 36bcf087cd9..ea406aadf39 100644 --- a/scripts/prepare_build.sh +++ b/scripts/prepare_build.sh @@ -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` -- cgit v1.2.1