Commit 74e5ec19 authored by Stan Hu's avatar Stan Hu

Fix failing ./spec/lib/backup/repository_spec.rb by clearing the memoized value

parent b1f15dfa
...@@ -331,6 +331,7 @@ class Repository ...@@ -331,6 +331,7 @@ class Repository
return unless empty? return unless empty?
expire_method_caches(%i(has_visible_content?)) expire_method_caches(%i(has_visible_content?))
raw_repository.expire_has_local_branches_cache
end end
def lookup_cache def lookup_cache
......
...@@ -232,6 +232,10 @@ module Gitlab ...@@ -232,6 +232,10 @@ module Gitlab
end end
end end
def expire_has_local_branches_cache
clear_memoization(:has_local_branches)
end
def has_local_branches? def has_local_branches?
strong_memoize(:has_local_branches) do strong_memoize(:has_local_branches) do
uncached_has_local_branches? uncached_has_local_branches?
......
...@@ -463,13 +463,14 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -463,13 +463,14 @@ describe Gitlab::Git::Repository, seed_helper: true do
it 'returns false when there are no branches' do it 'returns false when there are no branches' do
# Sanity check # Sanity check
expect(repository.uncached_has_local_branches?).to eq(true) expect(repository.has_local_branches?).to eq(true)
FileUtils.rm_rf(File.join(repository.path, 'packed-refs')) FileUtils.rm_rf(File.join(repository.path, 'packed-refs'))
heads_dir = File.join(repository.path, 'refs/heads') heads_dir = File.join(repository.path, 'refs/heads')
FileUtils.rm_rf(heads_dir) FileUtils.rm_rf(heads_dir)
FileUtils.mkdir_p(heads_dir) FileUtils.mkdir_p(heads_dir)
repository.expire_has_local_branches_cache
expect(repository.has_local_branches?).to eq(false) expect(repository.has_local_branches?).to eq(false)
end end
end end
......
...@@ -1437,6 +1437,12 @@ describe Repository do ...@@ -1437,6 +1437,12 @@ describe Repository do
repository.expire_emptiness_caches repository.expire_emptiness_caches
end end
it 'expires the memoized repository cache' do
allow(repository.raw_repository).to receive(:expire_has_local_branches_cache).and_call_original
repository.expire_emptiness_caches
end
end end
describe 'skip_merges option' do describe 'skip_merges option' do
......
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