raincoat 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +22 -9
- data/Rakefile +1 -1
- data/bin/raincoat +3 -3
- data/lib/raincoat/hook.rb +18 -5
- data/lib/raincoat/installer.rb +6 -10
- data/lib/raincoat/script_writer.rb +9 -17
- data/lib/raincoat.rb +2 -0
- metadata +4 -4
data/README.markdown
CHANGED
@@ -28,8 +28,8 @@ root directory of your project.
|
|
28
28
|
|
29
29
|
raincoat install
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
Make sure to back up any existing git hooks you have first as raincoat
|
32
|
+
will be writing its own hooks at this point.
|
33
33
|
|
34
34
|
Raincoat works by looking in your script directory for the directory
|
35
35
|
with the same name as the hook being executed, and then it runs each
|
@@ -38,13 +38,8 @@ executed it will look in `<script_dir>/pre-commit` and run each script
|
|
38
38
|
in there.
|
39
39
|
|
40
40
|
By default the script directory is set to `script` but a different
|
41
|
-
script directory can be specified by
|
42
|
-
|
43
|
-
|
44
|
-
raincoat install hooks
|
45
|
-
|
46
|
-
This would create a hooks directory where all of the hook scripts
|
47
|
-
could be placed.
|
41
|
+
script directory can be specified by defining it in the configuration
|
42
|
+
file (see below).
|
48
43
|
|
49
44
|
## Anatomy of a Raincoat Script
|
50
45
|
|
@@ -65,6 +60,24 @@ If the `call` method returns `false` then the operation will be
|
|
65
60
|
unsuccessful and git will not proceed. If it returns `true` the hook
|
66
61
|
will have a `0` exit status so git can continue.
|
67
62
|
|
63
|
+
## Configuring Raincoat
|
64
|
+
|
65
|
+
Raincoat is configured through a YAML file. By default raincoat checks
|
66
|
+
the root directory of the project for `raincoat.yml`, but a different
|
67
|
+
configuration file can be specified when installing raincoat into the
|
68
|
+
project by passing it to the install command
|
69
|
+
|
70
|
+
raincoat install my-config.yml
|
71
|
+
|
72
|
+
Will install raincoat to read the my-config.yml configuration file.
|
73
|
+
|
74
|
+
Raincoat can understand the following values in the configuration
|
75
|
+
file.
|
76
|
+
|
77
|
+
* `script_dir`: the base directory for raincoat scripts. The actual
|
78
|
+
scripts will be in something like `<script_dir>/precommit`
|
79
|
+
|
68
80
|
## TODO
|
69
81
|
|
70
82
|
* Add support for additional git-hooks
|
83
|
+
* Change diff passed to hooks from raw string to real object
|
data/Rakefile
CHANGED
data/bin/raincoat
CHANGED
@@ -4,9 +4,9 @@ $LOAD_PATH.unshift(raincoat_dir) unless $LOAD_PATH.include?(raincoat_dir)
|
|
4
4
|
require 'raincoat'
|
5
5
|
|
6
6
|
unless ARGV[0] == 'install'
|
7
|
-
$stderr.puts "raincoat only supports installation. Try `raincoat install <
|
7
|
+
$stderr.puts "raincoat only supports installation. Try `raincoat install <config_file>`"
|
8
8
|
exit 1
|
9
9
|
end
|
10
10
|
|
11
|
-
script_dir = ARGV[1]
|
12
|
-
Raincoat::Installer.new
|
11
|
+
script_dir = ARGV[1]
|
12
|
+
Raincoat::Installer.new.install
|
data/lib/raincoat/hook.rb
CHANGED
@@ -8,12 +8,19 @@ module Raincoat
|
|
8
8
|
attr_reader :script_dir
|
9
9
|
|
10
10
|
# Create a new hook object that will execute the scripts located in
|
11
|
-
#
|
11
|
+
# specified directory.
|
12
12
|
#
|
13
|
-
# @param [String]
|
14
|
-
#
|
15
|
-
|
16
|
-
|
13
|
+
# @param [String] config_file the location of the file for the configuration
|
14
|
+
# @param [String] hook_dir the directory within the main script dir for this
|
15
|
+
# specific hook
|
16
|
+
def initialize(config_file, hook_dir)
|
17
|
+
if File.exists?(config_file)
|
18
|
+
config = YAML::load_file(config_file)
|
19
|
+
else
|
20
|
+
config = default_config
|
21
|
+
end
|
22
|
+
dir = config['script_dir'] || default_config['script_dir']
|
23
|
+
@script_dir = File.join(dir, hook_dir)
|
17
24
|
end
|
18
25
|
|
19
26
|
# This is called when the hook is executed by git's callbacks. It loads
|
@@ -63,5 +70,11 @@ module Raincoat
|
|
63
70
|
def class_name_for(file_name)
|
64
71
|
file_name.split(/\//).last.sub(/\.rb$/, '').split(/_/).map{ |s| s.capitalize }.join('')
|
65
72
|
end
|
73
|
+
|
74
|
+
def default_config
|
75
|
+
{
|
76
|
+
'script_dir' => 'script'
|
77
|
+
}
|
78
|
+
end
|
66
79
|
end
|
67
80
|
end
|
data/lib/raincoat/installer.rb
CHANGED
@@ -7,23 +7,19 @@ module Raincoat
|
|
7
7
|
# The list of currently supported hooks
|
8
8
|
HOOKS = [ "pre-commit", "post-commit" ]
|
9
9
|
|
10
|
-
# Create an installer that
|
10
|
+
# Create an installer that can install hooks to read the specified config
|
11
|
+
# file.
|
11
12
|
#
|
12
|
-
# @param [String]
|
13
|
-
|
14
|
-
|
15
|
-
@script_dir = script_dir
|
13
|
+
# @param [String] config_file the path to the raincoat configuration file
|
14
|
+
def initialize(config_file = nil)
|
15
|
+
@config_file = config_file
|
16
16
|
end
|
17
17
|
|
18
18
|
# Install raincoat hooks in the current project for each of the supported
|
19
19
|
# git-hook types. This will create the corresponding script directory if
|
20
20
|
# it doesn't exist
|
21
21
|
def install
|
22
|
-
|
23
|
-
FileUtils.mkdir_p(@script_dir)
|
24
|
-
end
|
25
|
-
|
26
|
-
writer = ScriptWriter.new(@script_dir)
|
22
|
+
writer = ScriptWriter.new(@config_file)
|
27
23
|
HOOKS.each do |hook|
|
28
24
|
writer.write(hook)
|
29
25
|
end
|
@@ -10,13 +10,15 @@ module Raincoat
|
|
10
10
|
# The directory where git stores it's hooks
|
11
11
|
GIT_HOOK_DIR = File.join(".git","hooks")
|
12
12
|
|
13
|
-
#
|
14
|
-
|
13
|
+
# The raincoat configuration file
|
14
|
+
attr_writer :config_file
|
15
|
+
|
16
|
+
# Create a new ScriptWriter that creates hooks for the specified config_file
|
17
|
+
# If no config file is specified it will use the default of 'raincoat.yml'
|
15
18
|
#
|
16
|
-
# @param [String]
|
17
|
-
|
18
|
-
|
19
|
-
@script_dir = script_dir
|
19
|
+
# @param [String] config_file the location of the configuration file
|
20
|
+
def initialize(config_file = nil)
|
21
|
+
@config_file = config_file || 'raincoat.yml'
|
20
22
|
end
|
21
23
|
|
22
24
|
# Write a new hook to the git directory called hook_name. Also, if there
|
@@ -25,7 +27,6 @@ module Raincoat
|
|
25
27
|
#
|
26
28
|
# @param [String] hook_name the name of the git-hook to write this file for
|
27
29
|
def write(hook_name)
|
28
|
-
init_script_directory(File.join(@script_dir, hook_name))
|
29
30
|
path = File.join(GIT_HOOK_DIR, hook_name)
|
30
31
|
|
31
32
|
if File.exists?(path)
|
@@ -44,18 +45,9 @@ module Raincoat
|
|
44
45
|
# @param [String] hook_name the name of the git-hook to build a script for
|
45
46
|
def build_script(hook_name)
|
46
47
|
hook_type = hook_name.sub(/-/, '')
|
47
|
-
script_dir = File.join(@script_dir, hook_name)
|
48
48
|
ERB.new(DEFAULT_TEMPLATE).result(binding)
|
49
49
|
end
|
50
50
|
|
51
|
-
private
|
52
|
-
|
53
|
-
def init_script_directory(dir)
|
54
|
-
unless File.directory? dir
|
55
|
-
FileUtils.mkdir_p dir
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
51
|
DEFAULT_TEMPLATE = <<TEMPLATE
|
60
52
|
#!/usr/bin/env ruby
|
61
53
|
require 'rubygems'
|
@@ -67,7 +59,7 @@ class ActiveHook < Raincoat::Hook
|
|
67
59
|
end
|
68
60
|
end
|
69
61
|
|
70
|
-
exit(ActiveHook.new("<%=
|
62
|
+
exit(ActiveHook.new("<%= @config_file %>", "<%= hook_type %>").run)
|
71
63
|
|
72
64
|
TEMPLATE
|
73
65
|
end
|
data/lib/raincoat.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: raincoat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Burrows
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-26 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -27,9 +27,9 @@ files:
|
|
27
27
|
- Rakefile
|
28
28
|
- bin/raincoat
|
29
29
|
- lib/raincoat/diff_utils.rb
|
30
|
-
- lib/raincoat/script_writer.rb
|
31
|
-
- lib/raincoat/installer.rb
|
32
30
|
- lib/raincoat/hook.rb
|
31
|
+
- lib/raincoat/installer.rb
|
32
|
+
- lib/raincoat/script_writer.rb
|
33
33
|
- lib/raincoat.rb
|
34
34
|
has_rdoc: true
|
35
35
|
homepage: http://github.com/rhburrows/raincoat
|