diff options
author | Douwe Maan <douwe@gitlab.com> | 2016-04-04 14:25:15 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2016-04-04 14:25:15 +0000 |
commit | ba7fcc9866588eb215fc69f5d8b73c77805e4eef (patch) | |
tree | 282f0a18f0b568c843213f8c1ca7711c852af055 | |
parent | df77df46f5df41b53eff4906a19b8523a007671b (diff) | |
parent | e6b5716785a31396c2aa8b044a087e8b2ca5fac3 (diff) | |
download | gitlab-ce-ba7fcc9866588eb215fc69f5d8b73c77805e4eef.tar.gz |
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
-rw-r--r-- | app/models/repository.rb | 16 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 25 | ||||
-rw-r--r-- | spec/workers/merge_worker_spec.rb | 2 |
3 files changed, 33 insertions, 10 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index bf76de61148..e80c2238402 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -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,10 +614,14 @@ 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 end diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 9242a6f1739..c5d5a1c2492 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -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 diff --git a/spec/workers/merge_worker_spec.rb b/spec/workers/merge_worker_spec.rb index b11c5de94e3..1abd87d7d33 100644 --- a/spec/workers/merge_worker_spec.rb +++ b/spec/workers/merge_worker_spec.rb @@ -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 |