Commit cf09c826 authored by Alejandro Rodríguez's avatar Alejandro Rodríguez

Re-enable gitaly migration for ref_name_for_sha after bugfixes

parent 9a10a6bf
...@@ -471,19 +471,19 @@ module Gitlab ...@@ -471,19 +471,19 @@ module Gitlab
# Returns a RefName for a given SHA # Returns a RefName for a given SHA
def ref_name_for_sha(ref_path, sha) def ref_name_for_sha(ref_path, sha)
# NOTE: This feature is intentionally disabled until raise ArgumentError, "sha can't be empty" unless sha.present?
# https://gitlab.com/gitlab-org/gitaly/issues/180 is resolved
# gitaly_migrate(:find_ref_name) do |is_enabled| gitaly_migrate(:find_ref_name) do |is_enabled|
# if is_enabled if is_enabled
# gitaly_ref_client.find_ref_name(sha, ref_path) gitaly_ref_client.find_ref_name(sha, ref_path)
# else else
args = %W(#{Gitlab.config.git.bin_path} for-each-ref --count=1 #{ref_path} --contains #{sha}) args = %W(#{Gitlab.config.git.bin_path} for-each-ref --count=1 #{ref_path} --contains #{sha})
# Not found -> ["", 0] # Not found -> ["", 0]
# Found -> ["b8d95eb4969eefacb0a58f6a28f6803f8070e7b9 commit\trefs/environments/production/77\n", 0] # Found -> ["b8d95eb4969eefacb0a58f6a28f6803f8070e7b9 commit\trefs/environments/production/77\n", 0]
Gitlab::Popen.popen(args, @path).first.split.last Gitlab::Popen.popen(args, @path).first.split.last
# end end
# end end
end end
# Returns commits collection # Returns commits collection
......
...@@ -28,7 +28,7 @@ module Gitlab ...@@ -28,7 +28,7 @@ module Gitlab
def find_ref_name(commit_id, ref_prefix) def find_ref_name(commit_id, ref_prefix)
request = Gitaly::FindRefNameRequest.new( request = Gitaly::FindRefNameRequest.new(
repository: @repository, repository: @gitaly_repo,
commit_id: commit_id, commit_id: commit_id,
prefix: ref_prefix prefix: ref_prefix
) )
......
...@@ -26,6 +26,7 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -26,6 +26,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
context 'with gitaly enabled' do context 'with gitaly enabled' do
before { stub_gitaly } before { stub_gitaly }
after { Gitlab::GitalyClient.clear_stubs! }
it 'gets the branch name from GitalyClient' do it 'gets the branch name from GitalyClient' do
expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name) expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name)
...@@ -120,6 +121,7 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -120,6 +121,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
context 'with gitaly enabled' do context 'with gitaly enabled' do
before { stub_gitaly } before { stub_gitaly }
after { Gitlab::GitalyClient.clear_stubs! }
it 'gets the branch names from GitalyClient' do it 'gets the branch names from GitalyClient' do
expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names) expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names)
...@@ -157,6 +159,7 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -157,6 +159,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
context 'with gitaly enabled' do context 'with gitaly enabled' do
before { stub_gitaly } before { stub_gitaly }
after { Gitlab::GitalyClient.clear_stubs! }
it 'gets the tag names from GitalyClient' do it 'gets the tag names from GitalyClient' do
expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names) expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names)
...@@ -1046,6 +1049,28 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -1046,6 +1049,28 @@ describe Gitlab::Git::Repository, seed_helper: true do
end end
end end
describe '#ref_name_for_sha' do
let(:ref_path) { 'refs/heads' }
let(:sha) { repository.find_branch('master').dereferenced_target.id }
let(:ref_name) { 'refs/heads/master' }
it 'returns the ref name for the given sha' do
expect(repository.ref_name_for_sha(ref_path, sha)).to eq(ref_name)
end
it "returns an empty name if the ref doesn't exist" do
expect(repository.ref_name_for_sha(ref_path, "000000")).to eq("")
end
it "raise an exception if the ref is empty" do
expect { repository.ref_name_for_sha(ref_path, "") }.to raise_error(ArgumentError)
end
it "raise an exception if the ref is nil" do
expect { repository.ref_name_for_sha(ref_path, nil) }.to raise_error(ArgumentError)
end
end
describe '#find_commits' do describe '#find_commits' do
it 'should return a return a collection of commits' do it 'should return a return a collection of commits' do
commits = repository.find_commits commits = repository.find_commits
......
...@@ -110,25 +110,14 @@ describe Repository, models: true do ...@@ -110,25 +110,14 @@ describe Repository, models: true do
end end
describe '#ref_name_for_sha' do describe '#ref_name_for_sha' do
context 'ref found' do
it 'returns the ref' do it 'returns the ref' do
allow_any_instance_of(Gitlab::Popen).to receive(:popen). allow(repository.raw_repository).to receive(:ref_name_for_sha).
and_return(["b8d95eb4969eefacb0a58f6a28f6803f8070e7b9 commit\trefs/environments/production/77\n", 0]) and_return('refs/environments/production/77')
expect(repository.ref_name_for_sha('bla', '0' * 40)).to eq 'refs/environments/production/77' expect(repository.ref_name_for_sha('bla', '0' * 40)).to eq 'refs/environments/production/77'
end end
end end
context 'ref not found' do
it 'returns nil' do
allow_any_instance_of(Gitlab::Popen).to receive(:popen).
and_return(["", 0])
expect(repository.ref_name_for_sha('bla', '0' * 40)).to eq nil
end
end
end
describe '#ref_exists?' do describe '#ref_exists?' do
context 'when ref exists' do context 'when ref exists' do
it 'returns true' do it 'returns true' do
...@@ -1917,12 +1906,18 @@ describe Repository, models: true do ...@@ -1917,12 +1906,18 @@ describe Repository, models: true do
describe '#is_ancestor?' do describe '#is_ancestor?' do
context 'Gitaly is_ancestor feature enabled' do context 'Gitaly is_ancestor feature enabled' do
it "asks Gitaly server if it's an ancestor" do let(:commit) { repository.commit }
commit = repository.commit let(:ancestor) { commit.parents.first }
expect(repository.raw_repository).to receive(:is_ancestor?).and_call_original
before do
allow(Gitlab::GitalyClient).to receive(:enabled?).and_return(true)
allow(Gitlab::GitalyClient).to receive(:feature_enabled?).with(:is_ancestor).and_return(true) allow(Gitlab::GitalyClient).to receive(:feature_enabled?).with(:is_ancestor).and_return(true)
end
it "asks Gitaly server if it's an ancestor" do
expect_any_instance_of(Gitlab::GitalyClient::Commit).to receive(:is_ancestor).with(ancestor.id, commit.id)
expect(repository.is_ancestor?(commit.id, commit.id)).to be true repository.is_ancestor?(ancestor.id, commit.id)
end end
end end
end end
......
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