BigW Consortium Gitlab

Commit ba7fcc98 by Douwe Maan

Merge branch 'update_repository_from_ee' into 'master'

Migrate Repository#local_branches from gitlab-ee. REF: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/249 This will help us to avoid posible merge conflicts when merging gitlab-ce to gitlab-ee See merge request !3496
parents df77df46 e6b57167
......@@ -72,7 +72,7 @@ class Repository
return @has_visible_content unless @has_visible_content.nil?
@has_visible_content = cache.fetch(:has_visible_content?) do
raw_repository.branch_count > 0
branch_count > 0
end
end
......@@ -173,7 +173,7 @@ class Repository
end
def branch_names
cache.fetch(:branch_names) { raw_repository.branch_names }
cache.fetch(:branch_names) { branches.map(&:name) }
end
def tag_names
......@@ -191,7 +191,7 @@ class Repository
end
def branch_count
@branch_count ||= cache.fetch(:branch_count) { raw_repository.branch_count }
@branch_count ||= cache.fetch(:branch_count) { branches.size }
end
def tag_count
......@@ -239,7 +239,7 @@ class Repository
def expire_branches_cache
cache.expire(:branch_names)
@branches = nil
@local_branches = nil
end
def expire_cache(branch_name = nil, revision = nil)
......@@ -614,9 +614,13 @@ class Repository
refs_contains_sha('tag', sha)
end
def branches
@branches ||= raw_repository.branches
def local_branches
@local_branches ||= rugged.branches.each(:local).map do |branch|
Gitlab::Git::Branch.new(branch.name, branch.target)
end
end
alias_method :branches, :local_branches
def tags
@tags ||= raw_repository.tags
......
......@@ -303,7 +303,7 @@ describe Repository, models: true do
describe 'when there are no branches' do
before do
allow(repository.raw_repository).to receive(:branch_count).and_return(0)
allow(repository).to receive(:branch_count).and_return(0)
end
it { is_expected.to eq(false) }
......@@ -311,13 +311,13 @@ describe Repository, models: true do
describe 'when there are branches' do
it 'returns true' do
expect(repository.raw_repository).to receive(:branch_count).and_return(3)
expect(repository).to receive(:branch_count).and_return(3)
expect(subject).to eq(true)
end
it 'caches the output' do
expect(repository.raw_repository).to receive(:branch_count).
expect(repository).to receive(:branch_count).
once.
and_return(3)
......@@ -436,7 +436,7 @@ describe Repository, models: true do
it 'expires the visible content cache' do
repository.has_visible_content?
expect(repository.raw_repository).to receive(:branch_count).
expect(repository).to receive(:branch_count).
once.
and_return(0)
......@@ -865,4 +865,21 @@ describe Repository, models: true do
repository.build_cache
end
end
describe '#local_branches' do
it 'returns the local branches' do
masterrev = repository.find_branch('master').target
create_remote_branch('joe', 'remote_branch', masterrev)
repository.add_branch(user, 'local_branch', masterrev)
expect(repository.local_branches.any? { |branch| branch.name == 'remote_branch' }).to eq(false)
expect(repository.local_branches.any? { |branch| branch.name == 'local_branch' }).to eq(true)
end
end
def create_remote_branch(remote_name, branch_name, target)
rugged = repository.rugged
rugged.references.create("refs/remotes/#{remote_name}/#{branch_name}", target)
end
end
......@@ -22,6 +22,8 @@ describe MergeWorker do
merge_request.reload
expect(merge_request).to be_merged
source_project.repository.expire_branches_cache
expect(source_project.repository.branch_names).not_to include('markdown')
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