diff options
-rw-r--r-- | changelogs/unreleased/zj-ref-contains-sha-mandatory.yml | 5 | ||||
-rw-r--r-- | lib/gitlab/git/repository.rb | 39 | ||||
-rw-r--r-- | spec/lib/gitlab/git/repository_spec.rb | 32 |
3 files changed, 18 insertions, 58 deletions
diff --git a/changelogs/unreleased/zj-ref-contains-sha-mandatory.yml b/changelogs/unreleased/zj-ref-contains-sha-mandatory.yml new file mode 100644 index 00000000000..61bdce43c0e --- /dev/null +++ b/changelogs/unreleased/zj-ref-contains-sha-mandatory.yml @@ -0,0 +1,5 @@ +--- +title: Refs containting sha checks are done by Gitaly +merge_request: +author: +type: other diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 29a3a35812c..25487f53999 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -1467,25 +1467,11 @@ module Gitlab end def branch_names_contains_sha(sha) - gitaly_migrate(:branch_names_contains_sha, - status: Gitlab::GitalyClient::MigrationStatus::OPT_OUT) do |is_enabled| - if is_enabled - gitaly_ref_client.branch_names_contains_sha(sha) - else - refs_contains_sha('refs/heads/', sha) - end - end + gitaly_ref_client.branch_names_contains_sha(sha) end def tag_names_contains_sha(sha) - gitaly_migrate(:tag_names_contains_sha, - status: Gitlab::GitalyClient::MigrationStatus::OPT_OUT) do |is_enabled| - if is_enabled - gitaly_ref_client.tag_names_contains_sha(sha) - else - refs_contains_sha('refs/tags/', sha) - end - end + gitaly_ref_client.tag_names_contains_sha(sha) end def search_files_by_content(query, ref) @@ -1620,27 +1606,6 @@ module Gitlab end end - def refs_contains_sha(refs_prefix, sha) - refs_prefix << "/" unless refs_prefix.ends_with?('/') - - # By forcing the output to %(refname) each line wiht a ref will start with - # the ref prefix. All other lines can be discarded. - args = %W(for-each-ref --contains=#{sha} --format=%(refname) #{refs_prefix}) - names, code = run_git(args) - - return [] unless code.zero? - - refs = [] - left_slice_count = refs_prefix.length - names.lines.each do |line| - next unless line.start_with?(refs_prefix) - - refs << encode_utf8(line.rstrip[left_slice_count..-1]) - end - - refs - end - def rugged_write_config(full_path:) rugged.config['gitlab.fullpath'] = full_path end diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index cce84276fe3..fcb690d8aa3 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -615,32 +615,22 @@ describe Gitlab::Git::Repository, seed_helper: true do end describe '#branch_names_contains_sha' do - shared_examples 'returning the right branches' do - let(:head_id) { repository.rugged.head.target.oid } - let(:new_branch) { head_id } - let(:utf8_branch) { 'branch-é' } + let(:head_id) { repository.rugged.head.target.oid } + let(:new_branch) { head_id } + let(:utf8_branch) { 'branch-é' } - before do - repository.create_branch(new_branch, 'master') - repository.create_branch(utf8_branch, 'master') - end - - after do - repository.delete_branch(new_branch) - repository.delete_branch(utf8_branch) - end - - it 'displays that branch' do - expect(repository.branch_names_contains_sha(head_id)).to include('master', new_branch, utf8_branch) - end + before do + repository.create_branch(new_branch, 'master') + repository.create_branch(utf8_branch, 'master') end - context 'when Gitaly is enabled' do - it_behaves_like 'returning the right branches' + after do + repository.delete_branch(new_branch) + repository.delete_branch(utf8_branch) end - context 'when Gitaly is disabled', :disable_gitaly do - it_behaves_like 'returning the right branches' + it 'displays that branch' do + expect(repository.branch_names_contains_sha(head_id)).to include('master', new_branch, utf8_branch) end end |