Skip to content

Commit

Permalink
Gracefully handle case where no standard input is provided
Browse files Browse the repository at this point in the history
Fixes #700.
  • Loading branch information
sds committed Jan 4, 2020
1 parent b4635a3 commit 7b80b0c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Overcommit Changelog

## master (unreleased)

* Fix case where no standard input is provided to `pre-push` hooks

## 0.52.0

* Fix `Mdl` to properly parse JSON output from `mdl`
Expand Down
4 changes: 2 additions & 2 deletions lib/overcommit/hook_context/pre_push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def remote_ref_deletion?
return @remote_ref_deletion if defined?(@remote_ref_deletion)

@remote_ref_deletion ||= input_lines.
first.
split(' ').
first&.
split(' ')&.
first == '(deleted)'
end

Expand Down
10 changes: 9 additions & 1 deletion spec/overcommit/hook_context/pre_push_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
describe '#remote_ref_deletion?' do
subject { context.remote_ref_deletion? }

let(:standard_input) { "#{local_ref} #{local_sha1} #{remote_ref} #{remote_sha1}\n" }

before do
input.stub(:read).and_return("#{local_ref} #{local_sha1} #{remote_ref} #{remote_sha1}\n")
input.stub(:read).and_return(standard_input)
end

context 'when pushing new branch to remote ref' do
Expand Down Expand Up @@ -56,6 +58,12 @@

it { should == true }
end

context 'when no standard input is provided' do
let(:standard_input) { '' }

it { should == false }
end
end

describe '#pushed_refs' do
Expand Down

0 comments on commit 7b80b0c

Please sign in to comment.