Commit ba7fcc98 authored by Douwe Maan's avatar 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 ...@@ -72,7 +72,7 @@ class Repository
return @has_visible_content unless @has_visible_content.nil? return @has_visible_content unless @has_visible_content.nil?
@has_visible_content = cache.fetch(:has_visible_content?) do @has_visible_content = cache.fetch(:has_visible_content?) do
raw_repository.branch_count > 0 branch_count > 0
end end
end end
...@@ -173,7 +173,7 @@ class Repository ...@@ -173,7 +173,7 @@ class Repository
end end
def branch_names def branch_names
cache.fetch(:branch_names) { raw_repository.branch_names } cache.fetch(:branch_names) { branches.map(&:name) }
end end
def tag_names def tag_names
...@@ -191,7 +191,7 @@ class Repository ...@@ -191,7 +191,7 @@ class Repository
end end
def branch_count def branch_count
@branch_count ||= cache.fetch(:branch_count) { raw_repository.branch_count } @branch_count ||= cache.fetch(:branch_count) { branches.size }
end end
def tag_count def tag_count
...@@ -239,7 +239,7 @@ class Repository ...@@ -239,7 +239,7 @@ class Repository
def expire_branches_cache def expire_branches_cache
cache.expire(:branch_names) cache.expire(:branch_names)
@branches = nil @local_branches = nil
end end
def expire_cache(branch_name = nil, revision = nil) def expire_cache(branch_name = nil, revision = nil)
...@@ -614,10 +614,14 @@ class Repository ...@@ -614,10 +614,14 @@ class Repository
refs_contains_sha('tag', sha) refs_contains_sha('tag', sha)
end end
def branches def local_branches
@branches ||= raw_repository.branches @local_branches ||= rugged.branches.each(:local).map do |branch|
Gitlab::Git::Branch.new(branch.name, branch.target)
end
end end
alias_method :branches, :local_branches
def tags def tags
@tags ||= raw_repository.tags @tags ||= raw_repository.tags
end end
......
...@@ -303,7 +303,7 @@ describe Repository, models: true do ...@@ -303,7 +303,7 @@ describe Repository, models: true do
describe 'when there are no branches' do describe 'when there are no branches' do
before do before do
allow(repository.raw_repository).to receive(:branch_count).and_return(0) allow(repository).to receive(:branch_count).and_return(0)
end end
it { is_expected.to eq(false) } it { is_expected.to eq(false) }
...@@ -311,13 +311,13 @@ describe Repository, models: true do ...@@ -311,13 +311,13 @@ describe Repository, models: true do
describe 'when there are branches' do describe 'when there are branches' do
it 'returns true' 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) expect(subject).to eq(true)
end end
it 'caches the output' do it 'caches the output' do
expect(repository.raw_repository).to receive(:branch_count). expect(repository).to receive(:branch_count).
once. once.
and_return(3) and_return(3)
...@@ -436,7 +436,7 @@ describe Repository, models: true do ...@@ -436,7 +436,7 @@ describe Repository, models: true do
it 'expires the visible content cache' do it 'expires the visible content cache' do
repository.has_visible_content? repository.has_visible_content?
expect(repository.raw_repository).to receive(:branch_count). expect(repository).to receive(:branch_count).
once. once.
and_return(0) and_return(0)
...@@ -865,4 +865,21 @@ describe Repository, models: true do ...@@ -865,4 +865,21 @@ describe Repository, models: true do
repository.build_cache repository.build_cache
end end
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 end
...@@ -22,6 +22,8 @@ describe MergeWorker do ...@@ -22,6 +22,8 @@ describe MergeWorker do
merge_request.reload merge_request.reload
expect(merge_request).to be_merged expect(merge_request).to be_merged
source_project.repository.expire_branches_cache
expect(source_project.repository.branch_names).not_to include('markdown') expect(source_project.repository.branch_names).not_to include('markdown')
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