Skip to content

Commit 99d4d9a

Browse files
author
Aiden Scandella
committed
Improve installer
Don't choke on non-directory or non-git directories: continue on and print a warning. This is useful so you can run `overcommit *` in a directory and just install to all of the matching targets that are Git repositories. Change-Id: Ie5b617f7753a617ac6405464aa3901b49b7fffd9 Reviewed-on: https://gerrit.causes.com/22813 Tested-by: jenkins <jenkins@causes.com> Reviewed-by: Joe Lencioni <joe.lencioni@causes.com>
1 parent a5aabbe commit 99d4d9a

File tree

5 files changed

+15
-3
lines changed

5 files changed

+15
-3
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
0.1.1
22

3+
* Make installer more robust
34
* Improve readme documentation
45
* Add template listing (-l) to CLI
56
* Add rspec and super-basic spec coverage

lib/overcommit.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'overcommit/configuration'
22
require 'overcommit/console_methods'
3+
require 'overcommit/errors'
34
require 'overcommit/git_hook'
45
require 'overcommit/hook_specific_check'
56
require 'overcommit/installer'

lib/overcommit/cli.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ def run
8484
installer = Installer.new(@options)
8585

8686
@options[:targets].each do |target|
87-
installer.install(target)
87+
begin
88+
installer.install(target)
89+
rescue NotAGitRepoError => e
90+
warning "Skipping #{target}: #{e}"
91+
end
8892
end
8993

9094
success 'Installation complete'

lib/overcommit/errors.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class NotAGitRepoError < StandardError
2+
# Nothing to see here
3+
end

lib/overcommit/installer.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ def initialize(options = {})
99

1010
def install(target)
1111
absolute_target = File.expand_path(target)
12-
unless File.directory?(File.join(absolute_target, '.git'))
12+
unless File.directory? absolute_target
13+
raise NotAGitRepoError, 'is a directory'
14+
end
1315

14-
raise ArgumentError, "#{target} does not appear to be a git repository"
16+
unless File.directory?(File.join(absolute_target, '.git'))
17+
raise NotAGitRepoError, 'does not appear to be a git repository'
1518
end
1619

1720
puts "Installing hooks into #{target}"

0 commit comments

Comments
 (0)