Skip to content

Commit dbab5f2

Browse files
committed
Rename include_branch_deletions to include_remote_ref_deletions
Upon further reflection, this API is not about remote branches, but remote refs. Change its name to reflect that.
1 parent a267427 commit dbab5f2

File tree

6 files changed

+36
-35
lines changed

6 files changed

+36
-35
lines changed

CHANGELOG.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
* Add `GoFmt` pre-commit hook
99
* Add `exclude_branches` hook option to disable hooks running on specific branches
1010
* Add `exclude_remotes` pre-push hook option to disable pre-push hooks running against specific remotes
11-
* Change default behavior of pre-push hooks to **not** run against deleted remote branches
12-
* Add `include_branch_deletions` pre-push hook option to allow running for a remote branch deletion
11+
* Change default behavior of pre-push hooks to **not** run against deleted remote refs
12+
* Add `include_remote_ref_deletions` pre-push hook option to allow running for a remote branch deletion
13+
* Rename `remote_branch_deletion?` pre-push hook helper to `remote_ref_deletion?`
1314

1415
## 0.51.0
1516

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +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.
231+
`include_remote_ref_deletions` | *`PrePush` hooks only.* By default, `PrePush` hooks will **not** run for pushes that delete a remote ref (i.e. branches or tags). Set to `true` to have the hook run even for deleted remote ref.
232232
`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).
233233
`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.
234234
`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

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Base < Overcommit::Hook::Base
1212
def run?
1313
super &&
1414
!exclude_remotes.include?(remote_name) &&
15-
(include_branch_deletions? || !@context.remote_branch_deletion?)
15+
(include_remote_ref_deletions? || !@context.remote_ref_deletion?)
1616
end
1717

1818
private
@@ -21,8 +21,8 @@ def exclude_remotes
2121
@config['exclude_remotes'] || []
2222
end
2323

24-
def include_branch_deletions?
25-
@config['include_branch_deletions']
24+
def include_remote_ref_deletions?
25+
@config['include_remote_ref_deletions']
2626
end
2727
end
2828
end

lib/overcommit/hook_context/pre_push.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ def remote_url
1313
@args[1]
1414
end
1515

16-
def remote_branch_deletion?
17-
return @remote_branch_deletion if defined? @remote_branch_deletion
16+
def remote_ref_deletion?
17+
return @remote_ref_deletion if defined?(@remote_ref_deletion)
1818

19-
@remote_branch_deletion ||= input_lines.
20-
first.
21-
split(' ').
22-
first == '(deleted)'
19+
@remote_ref_deletion ||= input_lines.
20+
first.
21+
split(' ').
22+
first == '(deleted)'
2323
end
2424

2525
def pushed_refs

spec/overcommit/hook/pre_push/base_spec.rb

+20-20
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
describe Overcommit::Hook::PrePush::Base do
66
let(:remote_name) { 'origin' }
7-
let(:remote_branch_deletion?) { false }
7+
let(:remote_ref_deletion?) { false }
88
let(:config) { double('config') }
99
let(:context) { double('context') }
1010
let(:hook) { described_class.new(config, context) }
@@ -14,7 +14,7 @@
1414

1515
before do
1616
allow(context).to receive(:remote_name).and_return(remote_name)
17-
allow(context).to receive(:remote_branch_deletion?).and_return(remote_branch_deletion?)
17+
allow(context).to receive(:remote_ref_deletion?).and_return(remote_ref_deletion?)
1818
allow(config).to receive(:for_hook).and_return(hook_config)
1919
end
2020

@@ -44,52 +44,52 @@
4444
end
4545
end
4646

47-
context 'with include_branch_deletions specified' do
47+
context 'with include_remote_ref_deletions specified' do
4848
let(:hook_config) do
49-
{ 'include_branch_deletions' => include_branch_deletions }
49+
{ 'include_remote_ref_deletions' => include_remote_ref_deletions }
5050
end
51-
let(:remote_branch_deletion?) { false }
52-
let(:include_branch_deletions) { false }
51+
let(:remote_ref_deletion?) { false }
52+
let(:include_remote_ref_deletions) { false }
5353

5454
context 'when remote branch is not being deleted' do
55-
let(:remote_branch_deletion?) { false }
55+
let(:remote_ref_deletion?) { false }
5656

57-
context 'when include_branch_deletions is not specified' do
58-
let(:include_branch_deletions) { nil }
57+
context 'when include_remote_ref_deletions is not specified' do
58+
let(:include_remote_ref_deletions) { nil }
5959

6060
it { subject.should == true }
6161
end
6262

63-
context 'when include_branch_deletions is false' do
64-
let(:include_branch_deletions) { false }
63+
context 'when include_remote_ref_deletions is false' do
64+
let(:include_remote_ref_deletions) { false }
6565

6666
it { subject.should == true }
6767
end
6868

69-
context 'when include_branch_deletions is true' do
70-
let(:include_branch_deletions) { true }
69+
context 'when include_remote_ref_deletions is true' do
70+
let(:include_remote_ref_deletions) { true }
7171

7272
it { subject.should == true }
7373
end
7474
end
7575

7676
context 'when remote branch is being deleted' do
77-
let(:remote_branch_deletion?) { true }
77+
let(:remote_ref_deletion?) { true }
7878

79-
context 'when include_branch_deletions is not specified' do
80-
let(:include_branch_deletions) { nil }
79+
context 'when include_remote_ref_deletions is not specified' do
80+
let(:include_remote_ref_deletions) { nil }
8181

8282
it { subject.should == false }
8383
end
8484

85-
context 'when include_branch_deletions is false' do
86-
let(:include_branch_deletions) { false }
85+
context 'when include_remote_ref_deletions is false' do
86+
let(:include_remote_ref_deletions) { false }
8787

8888
it { subject.should == false }
8989
end
9090

91-
context 'when include_branch_deletions is true' do
92-
let(:include_branch_deletions) { true }
91+
context 'when include_remote_ref_deletions is true' do
92+
let(:include_remote_ref_deletions) { true }
9393

9494
it { subject.should == true }
9595
end

spec/overcommit/hook_context/pre_push_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
it { should == remote_url }
2424
end
2525

26-
describe '#remote_branch_deletion?' do
27-
subject { context.remote_branch_deletion? }
26+
describe '#remote_ref_deletion?' do
27+
subject { context.remote_ref_deletion? }
2828

2929
before do
3030
input.stub(:read).and_return("#{local_ref} #{local_sha1} #{remote_ref} #{remote_sha1}\n")
@@ -70,7 +70,7 @@
7070
input.stub(:read).and_return("#{local_ref} #{local_sha1} #{remote_ref} #{remote_sha1}\n")
7171
end
7272

73-
it 'should parse commit info from the input' do
73+
it 'parses commit info from the input' do
7474
pushed_refs.length.should == 1
7575
pushed_refs.each do |pushed_ref|
7676
pushed_ref.local_ref.should == local_ref

0 commit comments

Comments
 (0)