Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/overcommit/hook/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ def exclude_branch_patterns
@config['exclude_branch_patterns'] || []
end

def exclude_remote_names
@config['exclude_remote_names'] || []
end

def current_branch
@current_branch ||= Overcommit::GitRepo.current_branch
end
Expand Down
4 changes: 4 additions & 0 deletions lib/overcommit/hook/pre_push/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ class Base < Overcommit::Hook::Base
extend Forwardable

def_delegators :@context, :remote_name, :remote_url, :pushed_refs

def skip?
super || exclude_remote_names.include?(remote_name)
end
end
end
83 changes: 83 additions & 0 deletions spec/overcommit/hook/pre_push/base_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# frozen_string_literal: true

require 'spec_helper'

describe Overcommit::Hook::PrePush::Base do
let(:remote_name) { 'origin' }
let(:config) { double('config') }
let(:context) { double('context') }
let(:hook) { described_class.new(config, context) }
describe '#run?' do
let(:hook_config) do
{ 'skip' => skip }
end

before do
allow(context).to receive(:remote_name).and_return(remote_name)
allow(config).to receive(:for_hook).and_return(hook_config)
end

subject { hook.skip? }

context 'skip is true' do
let(:skip) { true }

it { subject.should == true }
end

context 'skip is false' do
let(:skip) { false }

it { subject.should == false }
end

context 'with exclude_remote_names specified' do
let(:hook_config) do
{ 'skip' => skip, 'exclude_remote_names' => exclude_remote_names }
end
let(:exclude_remote_names) { nil }

context 'skip is true and exclude_remote_names is nil' do
let(:skip) { true }
let(:exclude_remote_names) { nil }

it { subject.should == true }
end

context 'skip is false and exclude_remote_names is nil' do
let(:skip) { false }
let(:exclude_remote_names) { nil }

it { subject.should == false }
end

context 'skip is true and matching exclude_remote_names is nil' do
let(:skip) { true }
let(:exclude_remote_names) { ['origin'] }

it { subject.should == true }
end

context 'skip is false and matching exclude_remote_names is nil' do
let(:skip) { false }
let(:exclude_remote_names) { ['origin'] }

it { subject.should == true }
end

context 'skip is true and non-matching exclude_remote_names is nil' do
let(:skip) { true }
let(:exclude_remote_names) { ['heroku'] }

it { subject.should == true }
end

context 'skip is false and non-matching exclude_remote_names is nil' do
let(:skip) { false }
let(:exclude_remote_names) { ['heroku'] }

it { subject.should == false }
end
end
end
end