Commit 65a4b948 authored by Robert May's avatar Robert May Committed by Douglas Barbosa Alexandre

Add ListRefs bindings

parent df675c00
...@@ -784,6 +784,12 @@ module Gitlab ...@@ -784,6 +784,12 @@ module Gitlab
end end
end end
def list_refs
wrapped_gitaly_errors do
gitaly_ref_client.list_refs
end
end
# Refactoring aid; allows us to copy code from app/models/repository.rb # Refactoring aid; allows us to copy code from app/models/repository.rb
def commit(ref = 'HEAD') def commit(ref = 'HEAD')
Gitlab::Git::Commit.find(self, ref) Gitlab::Git::Commit.find(self, ref)
......
...@@ -194,6 +194,16 @@ module Gitlab ...@@ -194,6 +194,16 @@ module Gitlab
raise ArgumentError, ex raise ArgumentError, ex
end end
def list_refs(patterns = [Gitlab::Git::BRANCH_REF_PREFIX])
request = Gitaly::ListRefsRequest.new(
repository: @gitaly_repo,
patterns: patterns
)
response = GitalyClient.call(@storage, :ref_service, :list_refs, request, timeout: GitalyClient.fast_timeout)
consume_list_refs_response(response)
end
def pack_refs def pack_refs
request = Gitaly::PackRefsRequest.new(repository: @gitaly_repo) request = Gitaly::PackRefsRequest.new(repository: @gitaly_repo)
...@@ -206,6 +216,10 @@ module Gitlab ...@@ -206,6 +216,10 @@ module Gitlab
response.flat_map { |message| message.names.map { |name| yield(name) } } response.flat_map { |message| message.names.map { |name| yield(name) } }
end end
def consume_list_refs_response(response)
response.flat_map(&:references)
end
def sort_local_branches_by_param(sort_by) def sort_local_branches_by_param(sort_by)
sort_by = 'name' if sort_by == 'name_asc' sort_by = 'name' if sort_by == 'name_asc'
......
...@@ -1888,6 +1888,18 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do ...@@ -1888,6 +1888,18 @@ RSpec.describe Gitlab::Git::Repository, :seed_helper do
end end
end end
describe '#list_refs' do
it 'returns a list of branches with their head commit' do
refs = repository.list_refs
reference = refs.first
expect(refs).to be_an(Enumerable)
expect(reference).to be_a(Gitaly::ListRefsResponse::Reference)
expect(reference.name).to be_a(String)
expect(reference.target).to be_a(String)
end
end
describe '#set_full_path' do describe '#set_full_path' do
before do before do
repository_rugged.config["gitlab.fullpath"] = repository_path repository_rugged.config["gitlab.fullpath"] = repository_path
......
...@@ -252,6 +252,26 @@ RSpec.describe Gitlab::GitalyClient::RefService do ...@@ -252,6 +252,26 @@ RSpec.describe Gitlab::GitalyClient::RefService do
end end
end end
describe '#list_refs' do
it 'sends a list_refs message' do
expect_any_instance_of(Gitaly::RefService::Stub)
.to receive(:list_refs)
.with(gitaly_request_with_params(patterns: ['refs/heads/']), kind_of(Hash))
.and_call_original
client.list_refs
end
it 'accepts a patterns argument' do
expect_any_instance_of(Gitaly::RefService::Stub)
.to receive(:list_refs)
.with(gitaly_request_with_params(patterns: ['refs/tags/']), kind_of(Hash))
.and_call_original
client.list_refs([Gitlab::Git::TAG_REF_PREFIX])
end
end
describe '#pack_refs' do describe '#pack_refs' do
it 'sends a pack_refs message' do it 'sends a pack_refs message' do
expect_any_instance_of(Gitaly::RefService::Stub) expect_any_instance_of(Gitaly::RefService::Stub)
......
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