diff options
author | Stan Hu <stanhu@gmail.com> | 2016-08-29 17:46:30 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2016-09-01 10:08:23 +0300 |
commit | d326d3428da89b943bb5f1d4d396f21b3e999ff7 (patch) | |
tree | 218de7018f84bd040671f6fd87b4b760d363f63f /spec | |
parent | 1c4e866348e0c782d2e5374209508785ac812c7a (diff) |
Optimize branch lookups and force a repository reload for Repository#find_branch
If `git gc` runs and `Repository` has an instance to `Rugged::Repository`, a
bug in libgit2 may cause the instance to return a stale value or a missing
branch. This change not only optimizes the branch lookup so we don't have
to iterate through every branch, but it also works around the `git gc`
issue by forcing a repository reload every time `Repository#find_branch`
is called.
See: https://github.com/libgit2/libgit2/issues/1534
Closes #15392, #21470
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/repository_spec.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 1fea50ad42c..812c72c48cb 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -382,6 +382,24 @@ describe Repository, models: true do end end + describe '#find_branch' do + it 'loads a branch with a fresh repo' do + expect(Gitlab::Git::Repository).to receive(:new).twice.and_call_original + + 2.times do + expect(repository.find_branch('feature')).not_to be_nil + end + end + + it 'loads a branch with a cached repo' do + expect(Gitlab::Git::Repository).to receive(:new).once.and_call_original + + 2.times do + expect(repository.find_branch('feature', fresh_repo: false)).not_to be_nil + end + end + end + describe '#rm_branch' do let(:old_rev) { '0b4bc9a49b562e85de7cc9e834518ea6828729b9' } # git rev-parse feature let(:blank_sha) { '0000000000000000000000000000000000000000' } |