Skip to content

Commit 9bcfcb5

Browse files
committed
Rename ignore_branch_deletions to include_branch_deletions
This emphasizes that the default is not to include remote branch deletions, and uses language like "include" which is already used in other option names.
1 parent 34c4398 commit 9bcfcb5

File tree

3 files changed

+48
-113
lines changed

3 files changed

+48
-113
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ Option | Description
228228
`exclude` | File paths or glob patterns of files that do not apply to this hook. This is used to exclude any files that would have been matched by `include`.
229229
`exclude_branches` | List of branch names or glob patterns of branches that this hook should not run against.
230230
`exclude_remotes` | *`PrePush` hooks only.* List of remote names that the hook should not run against.
231+
`include_branch_deletions` | *`PrePush` hooks only.* By default, `PrePush` hooks will **not** run for pushes that delete a remote branch. Set to `true` to have the hook run even for deleted remote branches.
231232
`problem_on_unmodified_line` | How to treat errors reported on lines that weren't modified during the action captured by this hook (e.g. for pre-commit hooks, warnings/errors reported on lines that were not staged with `git add` may not be warnings/errors you care about). Valid values are `report`: report errors/warnings as-is regardless of line location (default); `warn`: report errors as warnings if they are on lines you didn't modify; and `ignore`: don't display errors/warnings at all if they are on lines you didn't modify (`ignore` is _not_ recommended).
232233
`on_fail` | Change the status of a failed hook to `warn` or `pass`. This allows you to treat failures as warnings or potentially ignore them entirely, but you should use caution when doing so as you might be hiding important information.
233234
`on_warn` | Similar to `on_fail`, change the status of a hook that returns a warning status to either `pass` (you wish to silence warnings entirely) or `fail` (you wish to treat all warnings as errors).

lib/overcommit/hook/pre_push/base.rb

+6-10
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,20 @@ class Base < Overcommit::Hook::Base
99

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

12-
def skip?
13-
super ||
14-
exclude_remotes.include?(remote_name) ||
15-
skip_for_remote_branch_deletion?
12+
def run?
13+
super &&
14+
!exclude_remotes.include?(remote_name) &&
15+
(include_branch_deletions? || !@context.remote_branch_deletion?)
1616
end
1717

1818
private
1919

20-
def skip_for_remote_branch_deletion?
21-
ignore_branch_deletions? && @context.remote_branch_deletion?
22-
end
23-
2420
def exclude_remotes
2521
@config['exclude_remotes'] || []
2622
end
2723

28-
def ignore_branch_deletions?
29-
@config['ignore_branch_deletions'] != false
24+
def include_branch_deletions?
25+
@config['include_branch_deletions']
3026
end
3127
end
3228
end

spec/overcommit/hook/pre_push/base_spec.rb

+41-103
Original file line numberDiff line numberDiff line change
@@ -8,153 +8,91 @@
88
let(:config) { double('config') }
99
let(:context) { double('context') }
1010
let(:hook) { described_class.new(config, context) }
11+
1112
describe '#run?' do
12-
let(:hook_config) do
13-
{ 'skip' => skip }
14-
end
13+
let(:hook_config) { {} }
1514

1615
before do
1716
allow(context).to receive(:remote_name).and_return(remote_name)
1817
allow(context).to receive(:remote_branch_deletion?).and_return(remote_branch_deletion?)
1918
allow(config).to receive(:for_hook).and_return(hook_config)
2019
end
2120

22-
subject { hook.skip? }
23-
24-
context 'skip is true' do
25-
let(:skip) { true }
26-
27-
it { subject.should == true }
28-
end
29-
30-
context 'skip is false' do
31-
let(:skip) { false }
32-
33-
it { subject.should == false }
34-
end
21+
subject { hook.run? }
3522

3623
context 'with exclude_remotes specified' do
3724
let(:hook_config) do
38-
{ 'skip' => skip, 'exclude_remotes' => exclude_remotes }
25+
{ 'exclude_remotes' => exclude_remotes }
3926
end
40-
let(:exclude_remotes) { nil }
4127

42-
context 'skip is true and exclude_remotes is nil' do
43-
let(:skip) { true }
28+
context 'exclude_remotes is nil' do
4429
let(:exclude_remotes) { nil }
4530

4631
it { subject.should == true }
4732
end
4833

49-
context 'skip is false and exclude_remotes is nil' do
50-
let(:skip) { false }
51-
let(:exclude_remotes) { nil }
52-
end
34+
context 'exclude_remotes includes the remote' do
35+
let(:exclude_remotes) { [remote_name] }
5336

54-
context 'skip is true and matching exclude_remotes is nil' do
55-
let(:skip) { true }
56-
let(:exclude_remotes) { ['origin'] }
57-
58-
it { subject.should == true }
59-
end
60-
61-
context 'skip is false and matching exclude_remotes is nil' do
62-
let(:skip) { false }
63-
let(:exclude_remotes) { ['origin'] }
37+
it { subject.should == false }
6438
end
6539

66-
context 'skip is true and non-matching exclude_remotes is nil' do
67-
let(:skip) { true }
40+
context 'exclude_remotes does not include the remote' do
6841
let(:exclude_remotes) { ['heroku'] }
6942

7043
it { subject.should == true }
7144
end
72-
73-
context 'skip is false and non-matching exclude_remotes is nil' do
74-
let(:skip) { false }
75-
let(:exclude_remotes) { ['heroku'] }
76-
77-
it { subject.should == false }
78-
end
7945
end
8046

81-
context 'with ignore_branch_deletions specified' do
47+
context 'with include_branch_deletions specified' do
8248
let(:hook_config) do
83-
{ 'skip' => skip, 'ignore_branch_deletions' => ignore_branch_deletions }
49+
{ 'include_branch_deletions' => include_branch_deletions }
8450
end
8551
let(:remote_branch_deletion?) { false }
86-
let(:ignore_branch_deletions) { false }
87-
88-
context(<<~DESC) do
89-
skip is true and
90-
remote_branch_deletion? is false and
91-
ignore_branch_deletions false' do
92-
DESC
93-
let(:skip) { true }
52+
let(:include_branch_deletions) { false }
53+
54+
context 'when remote branch is not being deleted' do
9455
let(:remote_branch_deletion?) { false }
95-
let(:ignore_branch_deletions) { nil }
9656

97-
it { subject.should == true }
98-
end
57+
context 'when include_branch_deletions is not specified' do
58+
let(:include_branch_deletions) { nil }
9959

100-
context(<<~DESC) do
101-
skip is false and
102-
remote_branch_deletion? is false and
103-
ignore_branch_deletions false' do
104-
DESC
105-
let(:skip) { false }
106-
let(:remote_branch_deletion?) { false }
107-
let(:ignore_branch_deletions) { false }
60+
it { subject.should == true }
61+
end
10862

109-
it { subject.should == false }
110-
end
63+
context 'when include_branch_deletions is false' do
64+
let(:include_branch_deletions) { false }
11165

112-
context(<<~DESC) do
113-
skip is false and
114-
remote_branch_deletion? is true and
115-
ignore_branch_deletions false' do
116-
DESC
117-
let(:skip) { false }
118-
let(:remote_branch_deletion?) { true }
119-
let(:ignore_branch_deletions) { false }
66+
it { subject.should == true }
67+
end
12068

121-
it { subject.should == false }
69+
context 'when include_branch_deletions is true' do
70+
let(:include_branch_deletions) { true }
71+
72+
it { subject.should == true }
73+
end
12274
end
12375

124-
context(<<~DESC) do
125-
skip is false and
126-
remote_branch_deletion? is true and
127-
ignore_branch_deletions true' do
128-
DESC
129-
let(:skip) { false }
76+
context 'when remote branch is being deleted' do
13077
let(:remote_branch_deletion?) { true }
131-
let(:ignore_branch_deletions) { true }
13278

133-
it { subject.should == true }
134-
end
79+
context 'when include_branch_deletions is not specified' do
80+
let(:include_branch_deletions) { nil }
13581

136-
context(<<~DESC) do
137-
skip is false and
138-
remote_branch_deletion? is false and
139-
ignore_branch_deletions true' do
140-
DESC
141-
let(:skip) { false }
142-
let(:remote_branch_deletion?) { false }
143-
let(:ignore_branch_deletions) { true }
82+
it { subject.should == false }
83+
end
14484

145-
it { subject.should == false }
146-
end
85+
context 'when include_branch_deletions is false' do
86+
let(:include_branch_deletions) { false }
14787

148-
context(<<-DESC) do
149-
skip is true and
150-
remote_branch_deletion? is true and
151-
ignore_branch_deletions true' do
152-
DESC
153-
let(:skip) { true }
154-
let(:remote_branch_deletion?) { true }
155-
let(:ignore_branch_deletions) { true }
88+
it { subject.should == false }
89+
end
15690

157-
it { subject.should == true }
91+
context 'when include_branch_deletions is true' do
92+
let(:include_branch_deletions) { true }
93+
94+
it { subject.should == true }
95+
end
15896
end
15997
end
16098
end

0 commit comments

Comments
 (0)