Skip to content

Commit 336c495

Browse files
Hamed Asgharisds
Hamed Asghari
authored andcommitted
ProtectedBranches should be able to handle pushing tags gracefully
1 parent 87aa1cf commit 336c495

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/overcommit/hook/pre_push/protected_branches.rb

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def illegal_pushes
2121

2222
def protected?(remote_ref)
2323
ref_name = remote_ref[%r{refs/heads/(.*)}, 1]
24+
return false if ref_name.nil?
2425
protected_branch_patterns.any? do |pattern|
2526
File.fnmatch(pattern, ref_name)
2627
end

spec/overcommit/hook/pre_push/protected_branches_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,14 @@
9393
include_examples 'protected branch'
9494
end
9595
end
96+
97+
context 'when pushing tags' do
98+
let(:pushed_ref_name) { 'redundant' }
99+
100+
before do
101+
pushed_ref.stub(:remote_ref).and_return("refs/tags/#{pushed_ref_name}")
102+
end
103+
104+
it { should pass }
105+
end
96106
end

0 commit comments

Comments
 (0)