From 597d23617489d0b078c58b8c7b110a54ec71ff1a Mon Sep 17 00:00:00 2001 From: Hamed Asghari Date: Thu, 23 Mar 2017 13:05:58 -0700 Subject: [PATCH] ProtectedBranches should be able to handle pushing tags gracefully --- lib/overcommit/hook/pre_push/protected_branches.rb | 1 + .../hook/pre_push/protected_branches_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+) 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