Skip to content
This repository was archived by the owner on May 12, 2018. It is now read-only.

Commit c6dcd08

Browse files
committed
Ignore symbolic refs that point to deleted branches
1 parent c0652a5 commit c6dcd08

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
v 7.2.8
2+
- Ignore symbolic refs that point to deleted branches (Stan Hu)
3+
14
v 7.2.7
25
- Include branch/tag name in archive file and dirname
36

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ group :development do
66
gem 'rubocop'
77
gem 'coveralls', require: false
88
gem 'rspec'
9+
gem 'rspec-mocks'
910
gem 'webmock'
1011
gem 'guard'
1112
gem 'guard-rspec'

Gemfile.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ DEPENDENCIES
116116
pry
117117
rake
118118
rspec
119+
rspec-mocks
119120
rubocop
120121
simplecov
121122
webmock
123+
124+
BUNDLED WITH
125+
1.10.5

lib/gitlab_git/repository.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ def branch_names
5353
# Returns an Array of Branches
5454
def branches
5555
rugged.branches.map do |rugged_ref|
56-
Branch.new(rugged_ref.name, rugged_ref.target)
57-
end.sort_by(&:name)
56+
begin
57+
Branch.new(rugged_ref.name, rugged_ref.target)
58+
rescue Rugged::ReferenceError
59+
# Omit invalid branch
60+
end
61+
end.compact.sort_by(&:name)
5862
end
5963

6064
# Returns an Array of tag names

spec/repository_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,4 +637,17 @@
637637
@repo.rugged.config.delete('core.autocrlf')
638638
end
639639
end
640+
641+
describe '#branches with deleted branch' do
642+
before(:each) do
643+
ref = double()
644+
ref.stub(:name) { 'bad-branch' }
645+
ref.stub(:target) { raise Rugged::ReferenceError }
646+
repository.rugged.stub(:branches) { [ref] }
647+
end
648+
649+
it 'should return empty branches' do
650+
expect(repository.branches).to eq([])
651+
end
652+
end
640653
end

0 commit comments

Comments
 (0)