diff --git a/lib/overcommit/hook/pre_push/protected_branches.rb b/lib/overcommit/hook/pre_push/protected_branches.rb index 28e60810..e83ad8a1 100644 --- a/lib/overcommit/hook/pre_push/protected_branches.rb +++ b/lib/overcommit/hook/pre_push/protected_branches.rb @@ -21,6 +21,7 @@ def illegal_pushes def protected?(remote_ref) ref_name = remote_ref[%r{refs/heads/(.*)}, 1] + return false if ref_name.nil? protected_branch_patterns.any? do |pattern| File.fnmatch(pattern, ref_name) end diff --git a/spec/overcommit/hook/pre_push/protected_branches_spec.rb b/spec/overcommit/hook/pre_push/protected_branches_spec.rb index 652f679f..e94ce35e 100644 --- a/spec/overcommit/hook/pre_push/protected_branches_spec.rb +++ b/spec/overcommit/hook/pre_push/protected_branches_spec.rb @@ -93,4 +93,14 @@ include_examples 'protected branch' end end + + context 'when pushing tags' do + let(:pushed_ref_name) { 'redundant' } + + before do + pushed_ref.stub(:remote_ref).and_return("refs/tags/#{pushed_ref_name}") + end + + it { should pass } + end end