Skip to content

Commit

Permalink
Allow ReplaceBranch to use skip_if (#809)
Browse files Browse the repository at this point in the history
* Allow ReplaceBranch to use skip_if

* Fix linting error

* Clearify specs

* Use bash instead of sh in spec
  • Loading branch information
oleander authored Mar 27, 2023
1 parent 2214dd1 commit 90e3679
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/overcommit/hook/prepare_commit_msg/replace_branch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def skipped_commit_types
end

def skip?
skipped_commit_types.include?(commit_message_source)
super || skipped_commit_types.include?(commit_message_source)
end
end
end
20 changes: 20 additions & 0 deletions spec/overcommit/hook/prepare_commit_msg/replace_branch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@ def remove_file(name)
expect(File.read('COMMIT_EDITMSG')).to eq("[123] \n")
end
end

context 'when skip_if exits with a zero status' do
let(:config) { new_config('skip_if' => ['bash', '-c', 'exit 0']) }

it { is_expected.to pass }

it 'does not change the commit message' do
expect(File.read('COMMIT_EDITMSG')).to eq("\n")
end
end

context 'when skip_if exits with a non-zero status' do
let(:config) { new_config('skip_if' => ['bash', '-c', 'exit 1']) }

it { is_expected.to pass }

it 'does change the commit message' do
expect(File.read('COMMIT_EDITMSG')).to eq("[#123]\n")
end
end
end

context "when the checked out branch doesn't matches the pattern" do
Expand Down

0 comments on commit 90e3679

Please sign in to comment.