git-hook 0.1.5 → 0.1.6
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/README.md +16 -16
- data/bin/githook +1 -1
- data/lib/githook/config.rb +1 -1
- data/lib/githook/tasks.rb +1 -1
- data/lib/githook/tasks/commit-msg.rake +2 -2
- data/lib/githook/tasks/install.rake +2 -2
- data/lib/githook/tasks/pre-commit.rake +4 -4
- data/lib/githook/tasks/prepare-commit-msg.rake +2 -2
- data/lib/githook/tasks/setup.rake +31 -31
- data/lib/githook/templates/config.rb +6 -6
- data/lib/githook/templates/tasks/{task.rake → tasks.rake} +2 -2
- data/lib/githook/util.rb +25 -25
- data/lib/githook/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba97bebb3ffa1f04ed26b75d27533f1cd8a27170
|
4
|
+
data.tar.gz: e0341ec6e8b724aa65662b68dfd9d5bb2e6c82e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd5d50ddce81355d61c1adde543673001e4431b55bead4439eac9ba7f460f622a8ac019bb0c0c0ff54c00b00e35b04b95f1d11def09d8387791078de9dea2624
|
7
|
+
data.tar.gz: aa75d443d787d04048913914ce068b81de38a47b5419f8486099ed25ff0ceab92f14082028a95ced0b32bfe976ec97c0ed17011b16d33e7ee9746275b93da804
|
data/README.md
CHANGED
@@ -91,7 +91,7 @@ We will execute `githook pre_commit` in `pre-commit`, if it fails, it will abort
|
|
91
91
|
|
92
92
|
What does `githook pre_commit` do? don't forget the githook base on Rake, so the `pre_commit` is a task defined in `tasks/pre-commit.rake`:
|
93
93
|
|
94
|
-
desc
|
94
|
+
desc "Run all pre-commit hook tasks"
|
95
95
|
task :pre_commit do |t|
|
96
96
|
Githook::Util.log_task(t.name)
|
97
97
|
Githook::Util.run_tasks(t.name.to_sym)
|
@@ -116,19 +116,19 @@ Where do we define the `:pre_commit` value? It is defined by user in `.githook/c
|
|
116
116
|
|
117
117
|
set :pre_commit, fetch(:pre_commit, []).push(
|
118
118
|
# uncomment following lines if it is a ruby project
|
119
|
-
#
|
120
|
-
#
|
119
|
+
# "pre_commit:rubocop",
|
120
|
+
# "pre_commit:rspec",
|
121
121
|
|
122
122
|
# uncomment following lines if it is an android or java project built by gradle
|
123
|
-
#
|
123
|
+
# "pre_commit:checkstyle"
|
124
124
|
)
|
125
125
|
set :prepare_commit_msg, fetch(:prepare_commit_msg, []).push(
|
126
126
|
# comment following lines if you want to skip it
|
127
|
-
|
127
|
+
"prepare_commit_msg:prepare"
|
128
128
|
)
|
129
129
|
set :commit_msg, fetch(:commit_msg, []).push(
|
130
130
|
# comment following lines if you want to skip it
|
131
|
-
|
131
|
+
"commit_msg:check_msg"
|
132
132
|
)
|
133
133
|
|
134
134
|
We use `set` method to set the value. It seems the `:pre_commit` value is an empty array by default, all items are commented, so `githook pre_commit` in `pre-commit` hook will do nothing, but if your project is a ruby or rails project, there are 2 default tasks are prepared for `:pre_commit`, they are `pre_commit:rubocop` and `pre_commit:rspec` (also has a default task `pre_commit:checkstyle` prepared for android or java project), if you uncomment the above 2 lines code, then `pre_commit:rubocp` and `pre_commit:rspec` will be executed when you commit code, of course, you can define your customized tasks and add to hooks (later I will introduce how to add a customized task).
|
@@ -136,19 +136,19 @@ We use `set` method to set the value. It seems the `:pre_commit` value is an emp
|
|
136
136
|
How do the default tasks `pre_commit:rubocop` and `pre_commit:rspec` look like, they are defined in `tasks/pre-commit.rake`:
|
137
137
|
|
138
138
|
namespace :pre_commit do
|
139
|
-
desc
|
139
|
+
desc "Check ruby code style by rubocop"
|
140
140
|
task :rubocop do |t|
|
141
141
|
Githook::Util.log_task(t.name)
|
142
142
|
exit 1 unless system("bundle exec rubocop")
|
143
143
|
end
|
144
144
|
|
145
|
-
desc
|
145
|
+
desc "Test ruby code by rspec"
|
146
146
|
task :rspec do |t|
|
147
147
|
Githook::Util.log_task(t.name)
|
148
148
|
exit 1 unless system("bundle exec rspec")
|
149
149
|
end
|
150
150
|
|
151
|
-
desc
|
151
|
+
desc "Check java code style by checkstyle"
|
152
152
|
task :checkstyle do |t|
|
153
153
|
Githook::Util.log_task(t.name)
|
154
154
|
exit 1 unless system("./gradlew checkstyle")
|
@@ -162,7 +162,7 @@ At last, let's see what do `prepare_commit_msg:prepare` and `commit_msg:check_ms
|
|
162
162
|
The `prepare_commit_msg:prepare` is defined in `tasks/prepare-commit-msg.rake`, it is executed in `prepare-commit-msg` hook. It will check whether the commit message is empty, if it is, it will help generate the commit message according the branch name, for example, if the branch name is `feature/24_add_help_task`, then the auto generated commit message is "FEATURE #24 - Add help task".
|
163
163
|
|
164
164
|
namespace :prepare_commit_msg do
|
165
|
-
desc
|
165
|
+
desc "Prepare commit msg"
|
166
166
|
task :prepare do |t|
|
167
167
|
Githook::Util.log_task(t.name)
|
168
168
|
|
@@ -181,7 +181,7 @@ The `prepare_commit_msg:prepare` is defined in `tasks/prepare-commit-msg.rake`,
|
|
181
181
|
The `commit_msg:check_msg` is defined in `tasks/commit-msg.rake`, it is executed in `commit-msg` hook after you save the commit message. It will check your commit message style, if it doesn't match the expected format, then this commit will be aborted. In default, our expected commit message summary format is "FEAUTER|BUG|MISC|REFACTOR #issue_num - Summary", if you prefer to use other format, you need to define yourself task to replace the default behavior.
|
182
182
|
|
183
183
|
namespace :commit_msg do
|
184
|
-
desc
|
184
|
+
desc "Check commit msg style"
|
185
185
|
task :check_msg do |t|
|
186
186
|
Githook::Util.log_task(t.name)
|
187
187
|
|
@@ -199,15 +199,15 @@ The default `pre_commit:rubocp`, `pre_commit:rspec` tasks will help you check ru
|
|
199
199
|
|
200
200
|
If you don't like these default behaviors, for example you have your own commit message style, or you want to add more checks, for example you want to be more strict in the branch name, you can't name a branch arbitrarily, it must follow some rules, it should be one of `develop/staging/master`, `/^(feature|bug|hotfix|misc|refactor)\/(\d*)?(\w*)/`, let's try to implement this custom task.
|
201
201
|
|
202
|
-
We can define it in any rake file in `.githook/tasks` folder, there is already an empty `
|
202
|
+
We can define it in any rake file in `.githook/tasks` folder, there is already an empty `tasks.rake` file, so let's just define in it. It should work in `pre-commit` hook, so let's define it in `:pre_commit` namespace.
|
203
203
|
|
204
|
-
# .githook/tasks/
|
204
|
+
# .githook/tasks/tasks.rake
|
205
205
|
namespace :pre_commit do
|
206
|
-
desc
|
206
|
+
desc "Check branch name style"
|
207
207
|
task :check_branch_name do
|
208
208
|
expected_branch_reg = /^(feature|bug|hotfix|misc|refactor)\/(\d*)?(\w*)/
|
209
209
|
branch_name = Githook::Util.branch_name
|
210
|
-
if branch_name.include?(
|
210
|
+
if branch_name.include?("/")
|
211
211
|
valid = expected_branch_reg.match(branch_name)
|
212
212
|
else
|
213
213
|
valid = %w(develop staging master).include?(branch_name)
|
@@ -223,7 +223,7 @@ Finally, don't forget to enable this task in `.githook/config.rb`:
|
|
223
223
|
|
224
224
|
# .githook/config.rb
|
225
225
|
set :pre_commit, fetch(:pre_commit, []).push(
|
226
|
-
|
226
|
+
"pre_commit:check_branch_name"
|
227
227
|
)
|
228
228
|
|
229
229
|
Demo:
|
data/bin/githook
CHANGED
data/lib/githook/config.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# we must be very careful to load outside ruby code
|
2
2
|
# because they are out of our control
|
3
3
|
# only load outside "*.rake" when there are ".git" and ".githook" folder, and target task isn't "install"
|
4
|
-
if Dir.exist?(
|
4
|
+
if Dir.exist?(".git") && Dir.exist?(".githook") && ARGV[0] != "install"
|
5
5
|
begin
|
6
6
|
load ".githook/config.rb"
|
7
7
|
rescue => e
|
data/lib/githook/tasks.rb
CHANGED
@@ -11,7 +11,7 @@ Dir.glob(rake_files_pattern).each { |r| load r }
|
|
11
11
|
# we must be very careful to load outside ruby code
|
12
12
|
# because they are out of our control
|
13
13
|
# only load outside "*.rake" when there are ".git" and ".githook" folder, and target task isn't "install"
|
14
|
-
if Dir.exist?(
|
14
|
+
if Dir.exist?(".git") && Dir.exist?(".githook") && ARGV[0] != "install"
|
15
15
|
Dir.glob(".githook/tasks/**/*.rake").each do |rake|
|
16
16
|
begin
|
17
17
|
load rake
|
@@ -1,5 +1,5 @@
|
|
1
1
|
namespace :commit_msg do
|
2
|
-
desc
|
2
|
+
desc "Check commit msg style"
|
3
3
|
task :check_msg do |t|
|
4
4
|
Githook::Util.log_task(t.name)
|
5
5
|
|
@@ -15,7 +15,7 @@ namespace :commit_msg do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
desc
|
18
|
+
desc "Run all commit-msg hook tasks"
|
19
19
|
task :commit_msg do |t|
|
20
20
|
Githook::Util.log_task(t.name)
|
21
21
|
Githook::Util.run_tasks(t.name.to_sym)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
desc
|
1
|
+
desc "Init githook, create .githook folder, prepare template files"
|
2
2
|
task :install do
|
3
3
|
# step 1, check whether Dir.pwd is in git repo root folder
|
4
4
|
git_path = ".git"
|
@@ -7,7 +7,7 @@ task :install do
|
|
7
7
|
exit 1
|
8
8
|
end
|
9
9
|
|
10
|
-
# step 2, check whether
|
10
|
+
# step 2, check whether ".githook" folder already exists
|
11
11
|
githook_path = ".githook"
|
12
12
|
if Dir.exists?(githook_path)
|
13
13
|
print ".githook already exists, do you want to override it? [y/(n)]: "
|
@@ -1,24 +1,24 @@
|
|
1
1
|
namespace :pre_commit do
|
2
|
-
desc
|
2
|
+
desc "Check ruby code style by rubocop"
|
3
3
|
task :rubocop do |t|
|
4
4
|
Githook::Util.log_task(t.name)
|
5
5
|
exit 1 unless system("bundle exec rubocop")
|
6
6
|
end
|
7
7
|
|
8
|
-
desc
|
8
|
+
desc "Test ruby code by rspec"
|
9
9
|
task :rspec do |t|
|
10
10
|
Githook::Util.log_task(t.name)
|
11
11
|
exit 1 unless system("bundle exec rspec")
|
12
12
|
end
|
13
13
|
|
14
|
-
desc
|
14
|
+
desc "Check java code style by checkstyle"
|
15
15
|
task :checkstyle do |t|
|
16
16
|
Githook::Util.log_task(t.name)
|
17
17
|
exit 1 unless system("./gradlew checkstyle")
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
desc
|
21
|
+
desc "Run all pre-commit hook tasks"
|
22
22
|
task :pre_commit do |t|
|
23
23
|
Githook::Util.log_task(t.name)
|
24
24
|
Githook::Util.run_tasks(t.name.to_sym)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
namespace :prepare_commit_msg do
|
2
|
-
desc
|
2
|
+
desc "Prepare commit msg"
|
3
3
|
task :prepare do |t|
|
4
4
|
Githook::Util.log_task(t.name)
|
5
5
|
|
@@ -20,7 +20,7 @@ namespace :prepare_commit_msg do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
desc
|
23
|
+
desc "Run all prepare-commit-msg hook tasks"
|
24
24
|
task :prepare_commit_msg do |t|
|
25
25
|
Githook::Util.log_task(t.name)
|
26
26
|
Githook::Util.run_tasks(t.name.to_sym)
|
@@ -1,15 +1,15 @@
|
|
1
|
-
desc
|
1
|
+
desc "Check whether .githook/hooks folder exists"
|
2
2
|
task :check_githook_folder do
|
3
|
-
hooks_path =
|
3
|
+
hooks_path = ".githook/hooks"
|
4
4
|
unless Dir.exists?(hooks_path)
|
5
5
|
puts "There isn't a .githook/hooks folder."
|
6
6
|
exit 1
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
desc
|
10
|
+
desc "Check whether .git/hooks folder exists"
|
11
11
|
task :check_git_folder do
|
12
|
-
git_path =
|
12
|
+
git_path = ".git/hooks"
|
13
13
|
unless Dir.exists?(git_path)
|
14
14
|
puts "There isn't a .git/hooks folder."
|
15
15
|
exit 1
|
@@ -18,9 +18,9 @@ end
|
|
18
18
|
|
19
19
|
#################################################################
|
20
20
|
|
21
|
-
desc
|
21
|
+
desc "Setup hooks, copy hooks from .githook/hooks to .git/hooks"
|
22
22
|
task :setup => [:check_githook_folder, :check_git_folder] do
|
23
|
-
# setup 1, check whether has
|
23
|
+
# setup 1, check whether has ".githook/hooks" and ".git" folder
|
24
24
|
# => [:check_githook_folder, :check_git_folder]
|
25
25
|
|
26
26
|
# setup 2, backup hooks
|
@@ -28,15 +28,15 @@ task :setup => [:check_githook_folder, :check_git_folder] do
|
|
28
28
|
Rake::Task[:backup].invoke
|
29
29
|
|
30
30
|
# setup 3, copy hooks to .git/hooks
|
31
|
-
FileUtils.cp_r(
|
31
|
+
FileUtils.cp_r(".githook/hooks", ".git")
|
32
32
|
end
|
33
33
|
|
34
|
-
desc
|
34
|
+
desc "Backup old hooks in .git/hooks"
|
35
35
|
task :backup => :check_git_folder do
|
36
36
|
has_backup = false
|
37
|
-
Dir.glob(
|
38
|
-
file_name = path.split(
|
39
|
-
next if file_name.include?(
|
37
|
+
Dir.glob(".git/hooks/*").each do |path|
|
38
|
+
file_name = path.split("/").last
|
39
|
+
next if file_name.include?(".")
|
40
40
|
|
41
41
|
appendix = ".#{Time.now.strftime("%Y%m%d%H%m%S")}.bak"
|
42
42
|
puts "Backup old #{file_name} to #{file_name}#{appendix}"
|
@@ -47,20 +47,20 @@ task :backup => :check_git_folder do
|
|
47
47
|
puts "You can run 'githook clearup' to delete these backup." if has_backup
|
48
48
|
end
|
49
49
|
|
50
|
-
desc
|
50
|
+
desc "Clear backup hooks in .git/hooks"
|
51
51
|
task :clearup => :check_git_folder do
|
52
|
-
backup = Dir.glob(
|
53
|
-
Githook::Util.interactive_delete_files(backup,
|
52
|
+
backup = Dir.glob(".git/hooks/*.bak")
|
53
|
+
Githook::Util.interactive_delete_files(backup, "backup hooks")
|
54
54
|
end
|
55
55
|
|
56
56
|
# later I think we don't need to clear hooks, use disable/enable replace them
|
57
|
-
# desc
|
57
|
+
# desc "Clear all hooks (include backup) in .git/hooks"
|
58
58
|
# task :clear => :clearup do |t|
|
59
59
|
# Githook::Util.log_task(t.name)
|
60
60
|
|
61
|
-
# hooks = Dir.glob(
|
62
|
-
# .reject { |path| path.split(
|
63
|
-
# Githook::Util.interactive_delete_files(hooks,
|
61
|
+
# hooks = Dir.glob(".git/hooks/*")
|
62
|
+
# .reject { |path| path.split("/").last.include?(".") }
|
63
|
+
# Githook::Util.interactive_delete_files(hooks, "hooks")
|
64
64
|
# end
|
65
65
|
|
66
66
|
# all hooks
|
@@ -83,14 +83,14 @@ end
|
|
83
83
|
# post_update
|
84
84
|
# )
|
85
85
|
|
86
|
-
desc
|
86
|
+
desc "Disable hooks: [HOOKS=pre_commit,commit_msg] githook disable"
|
87
87
|
task :disable => :check_git_folder do
|
88
|
-
target_hooks = (ENV[
|
88
|
+
target_hooks = (ENV["HOOKS"] || "").split(",")
|
89
89
|
target_hooks = Githook::Util.all_hooks if target_hooks.empty?
|
90
90
|
|
91
91
|
target_hooks.each do |hook|
|
92
|
-
hook_path = File.join(
|
93
|
-
disable_path = hook_path +
|
92
|
+
hook_path = File.join(".git/hooks", hook.gsub("_", "-"))
|
93
|
+
disable_path = hook_path + ".disable"
|
94
94
|
if File.file?(hook_path)
|
95
95
|
FileUtils.mv(hook_path, disable_path)
|
96
96
|
puts "Disable #{hook} hook."
|
@@ -102,14 +102,14 @@ task :disable => :check_git_folder do
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
-
desc
|
105
|
+
desc "Enable hooks: [HOOKS=pre_commit,commit_msg] githook enable"
|
106
106
|
task :enable => :check_git_folder do
|
107
|
-
target_hooks = (ENV[
|
107
|
+
target_hooks = (ENV["HOOKS"] || "").split(",")
|
108
108
|
target_hooks = Githook::Util.all_hooks if target_hooks.empty?
|
109
109
|
|
110
110
|
target_hooks.each do |hook|
|
111
|
-
hook_path = File.join(
|
112
|
-
disable_path = hook_path +
|
111
|
+
hook_path = File.join(".git/hooks", hook.gsub("_", "-"))
|
112
|
+
disable_path = hook_path + ".disable"
|
113
113
|
if File.file?(hook_path)
|
114
114
|
puts "#{hook} hook is arleady enabled, skip."
|
115
115
|
elsif File.file?(disable_path)
|
@@ -121,14 +121,14 @@ task :enable => :check_git_folder do
|
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
-
desc
|
124
|
+
desc "List all hooks"
|
125
125
|
task :list => :check_git_folder do
|
126
126
|
enabled_hooks = []
|
127
127
|
disabled_hooks = []
|
128
128
|
all_hooks = Githook::Util.all_hooks
|
129
129
|
all_hooks.each do |hook|
|
130
|
-
hook_path = File.join(
|
131
|
-
disable_path = hook_path +
|
130
|
+
hook_path = File.join(".git/hooks", hook.gsub("_", "-"))
|
131
|
+
disable_path = hook_path + ".disable"
|
132
132
|
if File.file?(hook_path)
|
133
133
|
enabled_hooks << hook
|
134
134
|
elsif File.file?(disable_path)
|
@@ -141,7 +141,7 @@ task :list => :check_git_folder do
|
|
141
141
|
disabled_hooks.each { |h| puts " * #{h}" }
|
142
142
|
end
|
143
143
|
|
144
|
-
desc
|
144
|
+
desc "Version"
|
145
145
|
task :version do
|
146
146
|
puts Githook::VERSION
|
147
147
|
end
|
@@ -157,7 +157,7 @@ TASKS_NAME = %w(
|
|
157
157
|
version
|
158
158
|
help
|
159
159
|
)
|
160
|
-
desc
|
160
|
+
desc "Help"
|
161
161
|
task :help do
|
162
162
|
puts "Usage: githook task_name"
|
163
163
|
puts
|
@@ -1,18 +1,18 @@
|
|
1
1
|
set :pre_commit, fetch(:pre_commit, []).push(
|
2
2
|
# uncomment following lines if it is a ruby project
|
3
|
-
#
|
4
|
-
#
|
3
|
+
# "pre_commit:rubocop",
|
4
|
+
# "pre_commit:rspec",
|
5
5
|
|
6
6
|
# uncomment following lines if it is a java project built by gradle
|
7
|
-
#
|
7
|
+
# "pre_commit:checkstyle"
|
8
8
|
|
9
|
-
#
|
9
|
+
# "pre_commit:check_branch_name"
|
10
10
|
)
|
11
11
|
set :prepare_commit_msg, fetch(:prepare_commit_msg, []).push(
|
12
12
|
# comment following lines if you want to skip it
|
13
|
-
|
13
|
+
"prepare_commit_msg:prepare"
|
14
14
|
)
|
15
15
|
set :commit_msg, fetch(:commit_msg, []).push(
|
16
16
|
# comment following lines if you want to skip it
|
17
|
-
|
17
|
+
"commit_msg:check_msg"
|
18
18
|
)
|
@@ -2,11 +2,11 @@
|
|
2
2
|
# or put them in a new .rake file
|
3
3
|
|
4
4
|
# namespace :pre_commit do
|
5
|
-
# desc
|
5
|
+
# desc "Check branch name style"
|
6
6
|
# task :check_branch_name do
|
7
7
|
# expected_branch_reg = /^(feature|bug|hotfix|misc|refactor)\/(\d*)?(\w*)/
|
8
8
|
# branch_name = Githook::Util.branch_name
|
9
|
-
# if branch_name.include?(
|
9
|
+
# if branch_name.include?("/")
|
10
10
|
# valid = expected_branch_reg.match(branch_name)
|
11
11
|
# else
|
12
12
|
# valid = %w(develop staging master).include?(branch_name)
|
data/lib/githook/util.rb
CHANGED
@@ -23,14 +23,14 @@ module Githook
|
|
23
23
|
else
|
24
24
|
puts "There are following #{type}:"
|
25
25
|
puts path_arr
|
26
|
-
print "Are you sure want to delete all of them [
|
26
|
+
print "Are you sure want to delete all of them [y/(n)]: "
|
27
27
|
# https://stackoverflow.com/a/40643667/2998877
|
28
28
|
choice = STDIN.gets
|
29
|
-
if ["
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
return if ["N", "n", "\n"].include?(choice[0])
|
30
|
+
|
31
|
+
path_arr.each do |path|
|
32
|
+
FileUtils.rm(path)
|
33
|
+
puts "Delete #{path}"
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -38,26 +38,26 @@ module Githook
|
|
38
38
|
#######################################################
|
39
39
|
|
40
40
|
# def self.enabled_hooks
|
41
|
-
# Dir.glob(
|
42
|
-
# .map { |path| path.split(
|
43
|
-
# .reject { |name| name.include?(
|
44
|
-
# .map { |name| name.gsub(
|
41
|
+
# Dir.glob(".git/hooks/*")
|
42
|
+
# .map { |path| path.split("/").last }
|
43
|
+
# .reject { |name| name.include?(".") }
|
44
|
+
# .map { |name| name.gsub("-", "_") }
|
45
45
|
# end
|
46
46
|
|
47
47
|
# include enabled_hooks and disabled_hooks
|
48
48
|
def self.all_hooks
|
49
|
-
Dir.glob(
|
50
|
-
.map { |path| path.split(
|
51
|
-
.select { |name| !name.include?(
|
52
|
-
.map { |name| name.gsub(
|
49
|
+
Dir.glob(".git/hooks/*")
|
50
|
+
.map { |path| path.split("/").last }
|
51
|
+
.select { |name| !name.include?(".") || name.include?(".disable") }
|
52
|
+
.map { |name| name.gsub(".disable", "") }
|
53
53
|
.uniq
|
54
|
-
.map { |name| name.gsub(
|
54
|
+
.map { |name| name.gsub("-", "_") }
|
55
55
|
end
|
56
56
|
|
57
57
|
#######################################################
|
58
58
|
|
59
59
|
def self.commit_msg_file
|
60
|
-
|
60
|
+
".git/COMMIT_EDITMSG"
|
61
61
|
end
|
62
62
|
|
63
63
|
def self.branch_name
|
@@ -67,9 +67,9 @@ module Githook
|
|
67
67
|
def self.get_commit_msg(commit_msg_file)
|
68
68
|
commit_msg = []
|
69
69
|
# trim begining empty lines
|
70
|
-
File.open(commit_msg_file,
|
70
|
+
File.open(commit_msg_file, "r") do |f|
|
71
71
|
f.readlines.each do |line|
|
72
|
-
next if line[0] ==
|
72
|
+
next if line[0] == "#"
|
73
73
|
next if commit_msg.empty? && line.strip.empty?
|
74
74
|
commit_msg << line
|
75
75
|
end
|
@@ -107,19 +107,19 @@ module Githook
|
|
107
107
|
issue_num = match_group[2]
|
108
108
|
issue_content = match_group[3]
|
109
109
|
|
110
|
-
issue_type =
|
110
|
+
issue_type = "BUG" if issue_type == "HOTFIX"
|
111
111
|
issue_num = " \##{issue_num}" unless issue_num.empty?
|
112
|
-
issue_content = issue_content.tr(
|
112
|
+
issue_content = issue_content.tr("_", " ").strip.capitalize
|
113
113
|
|
114
114
|
"#{issue_type}#{issue_num} - #{issue_content}"
|
115
115
|
else
|
116
|
-
|
116
|
+
"MISC - "
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
120
|
# write the pre msg at the begining of commit_msg_file
|
121
121
|
def self.prefill_msg(commit_msg_file, pre_msg)
|
122
|
-
File.open(commit_msg_file,
|
122
|
+
File.open(commit_msg_file, "r+") do |f|
|
123
123
|
ori_content = f.read
|
124
124
|
f.seek(0, IO::SEEK_SET)
|
125
125
|
f.puts pre_msg
|
@@ -132,11 +132,11 @@ module Githook
|
|
132
132
|
DEF_MSG_BODY_REG = /^- ([a-z].*)[^.]$/
|
133
133
|
DEF_MSG_BODY_FORMAT = "- detail"
|
134
134
|
def self.check_msg_format?(commit_msg_arr)
|
135
|
-
summary = commit_msg_arr[0] ||
|
136
|
-
second_line = commit_msg_arr[1] ||
|
135
|
+
summary = commit_msg_arr[0] || ""
|
136
|
+
second_line = commit_msg_arr[1] || ""
|
137
137
|
body = commit_msg_arr[2..-1] || []
|
138
138
|
|
139
|
-
valid = summary.start_with?(
|
139
|
+
valid = summary.start_with?("Merge branch") || DEF_MSG_SUMMARY_REG.match(summary)
|
140
140
|
unless valid
|
141
141
|
puts "Commit message summary \"#{summary}\" format isn't correct."
|
142
142
|
puts "Expected format: \"#{DEF_MSG_SUMMARY_FORMAT}\""
|
data/lib/githook/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-hook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- baurine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -87,7 +87,7 @@ files:
|
|
87
87
|
- lib/githook/templates/hooks/commit-msg
|
88
88
|
- lib/githook/templates/hooks/pre-commit
|
89
89
|
- lib/githook/templates/hooks/prepare-commit-msg
|
90
|
-
- lib/githook/templates/tasks/
|
90
|
+
- lib/githook/templates/tasks/tasks.rake
|
91
91
|
- lib/githook/util.rb
|
92
92
|
- lib/githook/version.rb
|
93
93
|
homepage: https://github.com/baurine/githook
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
112
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.6.
|
113
|
+
rubygems_version: 2.6.14
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: Setup git hooks easily
|