githooks 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +45 -2
- data/bin/githooks +4 -1
- data/lib/githooks/base.rb +8 -2
- data/lib/githooks/version.rb +1 -1
- data/lib/hooks/applypatch-msg +1 -1
- data/lib/hooks/commit-msg +1 -1
- data/lib/hooks/post-applypatch +1 -1
- data/lib/hooks/post-checkout +1 -1
- data/lib/hooks/post-commit +1 -1
- data/lib/hooks/post-merge +1 -1
- data/lib/hooks/post-receive +1 -1
- data/lib/hooks/post-rewrite +1 -1
- data/lib/hooks/post-update +1 -1
- data/lib/hooks/pre-applypatch +1 -1
- data/lib/hooks/pre-auto-gc +1 -1
- data/lib/hooks/pre-commit +1 -1
- data/lib/hooks/pre-rebase +1 -1
- data/lib/hooks/pre-receive +1 -1
- data/lib/hooks/prepare-commit-msg +1 -1
- data/lib/hooks/update +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -1,7 +1,18 @@
|
|
1
1
|
# Githooks
|
2
2
|
|
3
|
-
|
3
|
+
A framework to manage git hooks with your repository. Codes in *_githooks.rb will be executed by the framework.
|
4
4
|
|
5
|
+
## Convention
|
6
|
+
Githooks will look for files named as filename_githooks.rb in your repository. The typical directory structure with Githooks will look like this,
|
7
|
+
```
|
8
|
+
/Your repository
|
9
|
+
/lib
|
10
|
+
/app
|
11
|
+
...
|
12
|
+
/hooks
|
13
|
+
example_githooks.rb
|
14
|
+
example2_githooks.rb
|
15
|
+
```
|
5
16
|
## Installation
|
6
17
|
|
7
18
|
Add this line to your application's Gemfile:
|
@@ -18,8 +29,40 @@ Or install it yourself as:
|
|
18
29
|
|
19
30
|
## Usage
|
20
31
|
|
21
|
-
|
32
|
+
After the gem is installed, you need to initialize githooks in your repository.
|
22
33
|
|
34
|
+
$ githooks --init
|
35
|
+
|
36
|
+
Following key words can be used in your githooks.rb files
|
37
|
+
* applypatch_msg
|
38
|
+
* pre_applypatch
|
39
|
+
* post_applypatch
|
40
|
+
* pre_commit
|
41
|
+
* prepare_commit_msg
|
42
|
+
* commit_msg
|
43
|
+
* post_commit
|
44
|
+
* pre_rebase
|
45
|
+
* post_checkout
|
46
|
+
* post_merge
|
47
|
+
* pre_receive
|
48
|
+
* post_receive
|
49
|
+
* update
|
50
|
+
* post_update
|
51
|
+
* pre_auto_gc
|
52
|
+
* post_rewrite
|
53
|
+
|
54
|
+
## Example
|
55
|
+
```ruby
|
56
|
+
# dummy_githooks.rb
|
57
|
+
pre_commit do
|
58
|
+
puts "executed in pre commit hook"
|
59
|
+
end
|
60
|
+
|
61
|
+
commit_msg do
|
62
|
+
puts "executed in commit msg hook"
|
63
|
+
exit -1
|
64
|
+
end
|
65
|
+
```
|
23
66
|
## Contributing
|
24
67
|
|
25
68
|
1. Fork it
|
data/bin/githooks
CHANGED
@@ -21,11 +21,14 @@ options = OptionParser.new do |opts|
|
|
21
21
|
opts.separator ''
|
22
22
|
opts.separator 'Options:'
|
23
23
|
|
24
|
-
opts.on('-i', '--
|
24
|
+
opts.on('-i', '--init', 'Initialize githooks for the current repository') do
|
25
25
|
exit unless system("git rev-parse")
|
26
|
+
puts "Copying git hooks..."
|
26
27
|
git_root = `git rev-parse --show-toplevel`.chop
|
27
28
|
gem_root = File.expand_path "..", File.dirname($0)
|
28
29
|
FileUtils.cp_r(Dir["#{gem_root}/gems/githooks-#{Githooks::VERSION}/lib/hooks/*"], "#{git_root}/.git/hooks")
|
30
|
+
puts "git hooks initialized"
|
31
|
+
exit
|
29
32
|
end
|
30
33
|
|
31
34
|
opts.on( '-l', '--list', 'List supported git hooks') do
|
data/lib/githooks/base.rb
CHANGED
@@ -20,6 +20,11 @@ module Githooks
|
|
20
20
|
pre_auto_gc
|
21
21
|
post_rewrite]
|
22
22
|
class Base
|
23
|
+
|
24
|
+
def initialize(args = nil)
|
25
|
+
@args = args
|
26
|
+
end
|
27
|
+
|
23
28
|
def execute
|
24
29
|
lambda {
|
25
30
|
hooks = []
|
@@ -44,9 +49,10 @@ module Githooks
|
|
44
49
|
load file
|
45
50
|
end
|
46
51
|
|
47
|
-
env = Object.new
|
52
|
+
# env = Object.new
|
48
53
|
each_hook do |hook|
|
49
|
-
env.instance_eval &hook
|
54
|
+
# env.instance_eval &hook
|
55
|
+
hook.call @args
|
50
56
|
end
|
51
57
|
end
|
52
58
|
|
data/lib/githooks/version.rb
CHANGED
data/lib/hooks/applypatch-msg
CHANGED
data/lib/hooks/commit-msg
CHANGED
data/lib/hooks/post-applypatch
CHANGED
data/lib/hooks/post-checkout
CHANGED
data/lib/hooks/post-commit
CHANGED
data/lib/hooks/post-merge
CHANGED
data/lib/hooks/post-receive
CHANGED
data/lib/hooks/post-rewrite
CHANGED
data/lib/hooks/post-update
CHANGED
data/lib/hooks/pre-applypatch
CHANGED
data/lib/hooks/pre-auto-gc
CHANGED
data/lib/hooks/pre-commit
CHANGED
data/lib/hooks/pre-rebase
CHANGED
data/lib/hooks/pre-receive
CHANGED
data/lib/hooks/update
CHANGED