overcommit 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/config/templates.yml +4 -4
- data/lib/overcommit/cli.rb +8 -6
- data/lib/overcommit/installer.rb +67 -20
- data/lib/overcommit/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e133359ae61ef154b91a8194178ee5a89af7c5da
|
4
|
+
data.tar.gz: 6c9f6191fea07ac695999e4ea0a7ff48b1858010
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 426352f6c848e421e356761aff3d729c264f1dea63b6e411061eaed03f698eae30cad5fc9716765386dd32324c756ecf9d460cfa3030ad110d217e566f98ab4d
|
7
|
+
data.tar.gz: 099133f6f3f22074fea07a299ba94e73bef8e5a8cf2052656b10df81833d22f770282bc2e9931bb02ad5b92725348f3cd38fbfee711fc1e3e7143b41c105f94f
|
data/config/templates.yml
CHANGED
data/lib/overcommit/cli.rb
CHANGED
@@ -40,6 +40,10 @@ module Overcommit
|
|
40
40
|
@options[:template] = template
|
41
41
|
end
|
42
42
|
|
43
|
+
opts.on('--uninstall', 'Remove overcommit from target') do
|
44
|
+
@options[:uninstall] = true
|
45
|
+
end
|
46
|
+
|
43
47
|
opts.on('-e', '--exclude hook_name,...', Array,
|
44
48
|
'Exclude hooks from installation') do |excludes|
|
45
49
|
# Transform from:
|
@@ -76,22 +80,20 @@ module Overcommit
|
|
76
80
|
|
77
81
|
def run
|
78
82
|
if @options[:targets].nil? || @options[:targets].empty?
|
79
|
-
warning 'You must supply at least one directory
|
83
|
+
warning 'You must supply at least one directory'
|
80
84
|
puts @parser.help
|
81
85
|
exit 2
|
82
86
|
end
|
83
87
|
|
84
|
-
installer = Installer.new(@options)
|
85
|
-
|
86
88
|
@options[:targets].each do |target|
|
87
89
|
begin
|
88
|
-
|
90
|
+
Installer.new(@options, target).run
|
89
91
|
rescue NotAGitRepoError => e
|
90
92
|
warning "Skipping #{target}: #{e}"
|
91
93
|
end
|
92
94
|
end
|
93
95
|
|
94
|
-
success 'Installation complete
|
96
|
+
success "#{@options[:uninstall] ? 'Removal' : 'Installation'} complete"
|
95
97
|
|
96
98
|
rescue ArgumentError => ex
|
97
99
|
error "Installation failed: #{ex}"
|
@@ -101,7 +103,7 @@ module Overcommit
|
|
101
103
|
private
|
102
104
|
|
103
105
|
def print_help(message, ex = nil)
|
104
|
-
error ex
|
106
|
+
error ex.to_s + "\n" if ex
|
105
107
|
puts message
|
106
108
|
exit 0
|
107
109
|
end
|
data/lib/overcommit/installer.rb
CHANGED
@@ -3,44 +3,79 @@ require 'yaml'
|
|
3
3
|
|
4
4
|
module Overcommit
|
5
5
|
class Installer
|
6
|
-
def initialize(options
|
6
|
+
def initialize(options, target)
|
7
7
|
@options = options
|
8
|
+
@target = target
|
8
9
|
end
|
9
10
|
|
10
|
-
def
|
11
|
-
|
11
|
+
def run
|
12
|
+
validate_target
|
13
|
+
@options[:uninstall] ? uninstall : install
|
14
|
+
end
|
15
|
+
|
16
|
+
def install
|
17
|
+
puts "Installing hooks into #{@target}"
|
18
|
+
|
19
|
+
install_scripts
|
20
|
+
install_hooks
|
21
|
+
write_configuration
|
22
|
+
end
|
23
|
+
|
24
|
+
def uninstall
|
25
|
+
puts "Removing hooks from #{@target}"
|
26
|
+
|
27
|
+
uninstall_scripts
|
28
|
+
uninstall_hooks
|
29
|
+
rm_configuration
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def hook_path
|
35
|
+
absolute_target = File.expand_path @target
|
36
|
+
File.join(absolute_target, '.git/hooks')
|
37
|
+
end
|
38
|
+
|
39
|
+
def validate_target
|
40
|
+
absolute_target = File.expand_path @target
|
12
41
|
unless File.directory? absolute_target
|
13
|
-
raise NotAGitRepoError, 'is a directory'
|
42
|
+
raise NotAGitRepoError, 'is not a directory'
|
14
43
|
end
|
15
44
|
|
16
45
|
unless File.directory?(File.join(absolute_target, '.git'))
|
17
46
|
raise NotAGitRepoError, 'does not appear to be a git repository'
|
18
47
|
end
|
19
|
-
|
20
|
-
puts "Installing hooks into #{target}"
|
21
|
-
hook_path = File.join(absolute_target, '.git/hooks')
|
22
|
-
|
23
|
-
install_scripts(hook_path)
|
24
|
-
install_hooks(hook_path)
|
25
|
-
write_configuration(hook_path)
|
26
48
|
end
|
27
49
|
|
28
|
-
private
|
29
|
-
|
30
50
|
# Make helper scripts available locally inside the repo
|
31
|
-
def install_scripts
|
32
|
-
FileUtils.cp_r Utils.absolute_path('bin/scripts'),
|
51
|
+
def install_scripts
|
52
|
+
FileUtils.cp_r Utils.absolute_path('bin/scripts'), hook_path
|
33
53
|
end
|
34
54
|
|
35
55
|
# Install all available git hooks into the repo
|
36
|
-
def install_hooks
|
37
|
-
|
38
|
-
FileUtils.cp hook, File.join(
|
56
|
+
def install_hooks
|
57
|
+
hooks.each do |hook|
|
58
|
+
FileUtils.cp hook, File.join(hook_path, File.basename(hook))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def uninstall_hooks
|
63
|
+
hooks.each do |hook|
|
64
|
+
delete File.join(hook_path, File.basename(hook))
|
39
65
|
end
|
40
66
|
end
|
41
67
|
|
68
|
+
def uninstall_scripts
|
69
|
+
scripts = File.join(hook_path, 'scripts')
|
70
|
+
FileUtils.rm_r scripts rescue false
|
71
|
+
end
|
72
|
+
|
73
|
+
def hooks
|
74
|
+
Dir[Utils.absolute_path('bin/hooks/*')]
|
75
|
+
end
|
76
|
+
|
42
77
|
# Dump a YAML document containing requested configuration
|
43
|
-
def write_configuration
|
78
|
+
def write_configuration
|
44
79
|
template = @options.fetch(:template, 'default')
|
45
80
|
base_config = Overcommit.config.templates[template]
|
46
81
|
if base_config.nil?
|
@@ -54,9 +89,21 @@ module Overcommit
|
|
54
89
|
a + b
|
55
90
|
end
|
56
91
|
|
57
|
-
File.open(
|
92
|
+
File.open(configuration_location, 'w') do |config|
|
58
93
|
YAML.dump(base_config, config)
|
59
94
|
end
|
60
95
|
end
|
96
|
+
|
97
|
+
def rm_configuration
|
98
|
+
delete configuration_location
|
99
|
+
end
|
100
|
+
|
101
|
+
def configuration_location
|
102
|
+
File.join(hook_path, 'overcommit.yml')
|
103
|
+
end
|
104
|
+
|
105
|
+
def delete(file)
|
106
|
+
File.delete file rescue false
|
107
|
+
end
|
61
108
|
end
|
62
109
|
end
|
data/lib/overcommit/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: overcommit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Causes Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|