Skip to content

Commit 686c094

Browse files
author
Shane da Silva
committed
Add --force flag to always overwrite hooks
If a user attempted to install Overcommit hooks into a git repository that already had non-overcommit hooks, it would report an error. Allow the user to specify a `--force` flag which disables this error and ensures the hooks are installed, overwriting if necessary. Closes sds#7 Change-Id: I9390e5e122572444202f0b1ef8ae172a15c5b4dc Reviewed-on: http://gerrit.causes.com/36004 Tested-by: jenkins <jenkins@causes.com> Reviewed-by: Shane da Silva <shane@causes.com>
1 parent 773a5b5 commit 686c094

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* Add support for JRuby 1.7.9 in Ruby 1.9 mode
99
* Display more helpful error message when installing Overcommit into a repo
1010
that already has non-Overcommit hooks
11+
* Add `--force` flag allowing Overcommit to be installed in repositories that
12+
already contain non-Overcommit hooks (overwriting them in the process)
1113

1214
## 0.6.3
1315

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Command Line Flag | Description
9090
--------------------------|----------------------------------------------------
9191
`-i`/`--install` | Install Overcommit hooks in a repository
9292
`-u`/`--uninstall` | Remove Overcommit hooks from a repository
93+
`-f`/`--force` | Don't bail on install if other hooks already exist--overwrite them
9394
`-t`/`--template-dir` | Print location of template directory
9495
`-h`/`--help` | Show command-line flag documentation
9596
`-v`/`--version` | Show version

lib/overcommit/cli.rb

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ def parse_arguments
4545
@options[:action] = :install
4646
end
4747

48+
opts.on('-f', '--force', 'Overwrite any previously installed hooks') do
49+
@options[:force] = true
50+
end
51+
4852
opts.on('-t', '--template-dir', 'Print location of template directory') do
4953
@options[:action] = :template_dir
5054
end

spec/overcommit/installer_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@
8181
it 'does not raise an error' do
8282
expect { subject }.to_not raise_error
8383
end
84+
85+
it 'symlinks all supported hooks to the master hook' do
86+
subject
87+
Overcommit::Utils.supported_hook_types.all? do |hook_type|
88+
File.readlink(File.join(hooks_dir, hook_type)) == 'overcommit-hook'
89+
end
90+
end
8491
end
8592
end
8693
end

0 commit comments

Comments
 (0)