Skip to content

Commit 9cbffeb

Browse files
committed
Auto-sign config file when installing hooks the first time
Previously, we required users to explicitly run `overcommit --sign` in their repositories after running `overcommit --install`. This was slightly annoying and made for a poor user onboarding experience. For all practical purposes, the initial bootstrap case seems like one where ease of getting started with the tool trumps the risk of malicious code execution via hooks. It is reasonable to assume that a user who runs `overcommit --install` is accepting responsibility for hook code executed as of that point. It is only on subsequent changes to configuration/hooks that they should be warned to sign the config file/hooks appropriately.
1 parent d486e96 commit 9cbffeb

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

CHANGELOG.md

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

55
* Fix `forwarding to private method` warning on Ruby 2.4.x
66
* Update `childprocess` dependency to 0.6.x series
7+
* Auto-sign configuration file when installing hooks for the first time
78

89
## 0.38.0
910

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ mkdir important-project
101101
cd important-project
102102
git init
103103
overcommit --install
104-
overcommit --sign # See Security section below for explanation
105104
```
106105

107106
See the [Security](#security) section of the documentation to understand why

lib/overcommit/installer.rb

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ def install
3636
install_hook_files
3737
install_starter_config
3838

39+
# Auto-sign configuration file on install
40+
config(verify: false).update_signature!
41+
3942
log.success "Successfully installed hooks into #{@target}"
4043
end
4144

@@ -180,5 +183,10 @@ def overcommit_hook?(file)
180183
# doesn't exist. Standardize the behavior to return false.
181184
false
182185
end
186+
187+
# Returns the configuration for this repository.
188+
def config(options = {})
189+
Overcommit::ConfigurationLoader.new(log, options).load_repo_config
190+
end
183191
end
184192
end

spec/integration/configuration_signing_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
around do |example|
2929
repo do
30-
echo(config.to_yaml, '.overcommit.yml')
3130
`overcommit --install > #{File::NULL}`
31+
echo(config.to_yaml, '.overcommit.yml')
3232

3333
`overcommit --sign` if configuration_signed
3434
echo(new_config.to_yaml, '.overcommit.yml')

spec/integration/installing_overcommit_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
require 'spec_helper'
22

33
describe 'installing Overcommit' do
4+
let(:enable_verification) { true }
5+
6+
it 'signs the configuration file' do
7+
repo do
8+
`overcommit --install`
9+
touch('some-file')
10+
`git add some-file`
11+
result = shell(%w[git commit --allow-empty -m Test])
12+
result.status.should == 0
13+
end
14+
end
15+
416
context 'when template directory points to the Overcommit template directory' do
517
around do |example|
618
repo(template_dir: Overcommit::Installer::TEMPLATE_DIRECTORY) do

0 commit comments

Comments
 (0)