githooks 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -33,7 +33,7 @@ After the gem is installed, you need to initialize githooks in your repository.
33
33
 
34
34
  $ githooks --init
35
35
 
36
- Following key words can be used in your githooks.rb files
36
+ Following key words can be used in your filename_githooks.rb files
37
37
  * applypatch_msg
38
38
  * pre_applypatch
39
39
  * post_applypatch
@@ -51,6 +51,8 @@ Following key words can be used in your githooks.rb files
51
51
  * pre_auto_gc
52
52
  * post_rewrite
53
53
 
54
+ The framework enable you to group different git hooks in one file and manage hooks based on their functionalities. Arguments for a specific hook is yielded to its corresponding marco. For example, you can access commit file through commit_msg { |args| p args[0] }
55
+
54
56
  ## Example
55
57
  ```ruby
56
58
  # dummy_githooks.rb
@@ -58,11 +60,23 @@ pre_commit do
58
60
  puts "executed in pre commit hook"
59
61
  end
60
62
 
61
- commit_msg do
62
- puts "executed in commit msg hook"
63
- exit -1
63
+ commit_msg do |args|
64
+ git_root = `git rev-parse --show-toplevel`.chop
65
+
66
+ message_file = args[0]
67
+ message = File.read(git_root+'/'+message_file)
68
+
69
+ $regex = /\[ref: (\d+)\]/
70
+
71
+ if !$regex.match(message)
72
+ puts "[POLICY] Your message is not formatted correctly"
73
+ exit 1
74
+ end
64
75
  end
65
76
  ```
77
+
78
+ The example hook checks whether the commit message follows the provided pattern.
79
+
66
80
  ## Contributing
67
81
 
68
82
  1. Fork it
data/bin/githooks CHANGED
@@ -23,11 +23,13 @@ options = OptionParser.new do |opts|
23
23
 
24
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..."
27
- git_root = `git rev-parse --show-toplevel`.chop
28
- gem_root = File.expand_path "..", File.dirname($0)
29
- FileUtils.cp_r(Dir["#{gem_root}/gems/githooks-#{Githooks::VERSION}/lib/hooks/*"], "#{git_root}/.git/hooks")
30
- puts "git hooks initialized"
26
+ if ask "githooks --init will override your existing hooks, continue? ", false
27
+ puts "Copying git hooks..."
28
+ git_root = `git rev-parse --show-toplevel`.chop
29
+ gem_root = File.expand_path "..", File.dirname($0)
30
+ FileUtils.cp_r(Dir["#{gem_root}/gems/githooks-#{Githooks::VERSION}/lib/hooks/*"], "#{git_root}/.git/hooks")
31
+ puts "git hooks initialized"
32
+ end
31
33
  exit
32
34
  end
33
35
 
@@ -0,0 +1,15 @@
1
+ module Githooks
2
+ module Helper
3
+ def ask(question, default=true)
4
+ option_string = default ? '[Y/n]' : '[y/N]'
5
+ response = nil
6
+ while (response != "Y\n") && (response != "N\n") && (response != "\n")
7
+ print "#{question} #{option_string} "
8
+ response = gets
9
+ response.upcase!
10
+ end
11
+ return default if response == "\n"
12
+ return (response == "Y\n") ? true : false
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Githooks
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/githooks.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require "githooks/version"
2
2
  require "githooks/base"
3
+ require "githooks/helper"
3
4
 
4
- module Githooks
5
- # Your code goes here...
6
- end
5
+ self.extend Githooks::Helper
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: githooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-11 00:00:00.000000000 Z
12
+ date: 2012-10-12 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: git hooks framework in Ruby
15
15
  email:
@@ -29,6 +29,7 @@ files:
29
29
  - githooks.gemspec
30
30
  - lib/githooks.rb
31
31
  - lib/githooks/base.rb
32
+ - lib/githooks/helper.rb
32
33
  - lib/githooks/version.rb
33
34
  - lib/hooks/applypatch-msg
34
35
  - lib/hooks/commit-msg