git-hook 0.1.2 → 0.1.3
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/lib/githook/tasks/commit-msg.rake +1 -1
- data/lib/githook/tasks/setup.rake +53 -35
- data/lib/githook/util.rb +21 -1
- data/lib/githook/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd3b750cfbd6d3b3158be919978cccf9b9f3e391
|
4
|
+
data.tar.gz: 3063fc3f1b655c7062326457187e3e66fd7e8677
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3120664307138925564ad5f227cb54999010d103ac4c35d61f008be3047ed479e8ab0d20bc0059091e89618e07d40da3382fc0ea26b6fd72c9482b262a279392
|
7
|
+
data.tar.gz: 1b62f43c9006c333af6e8ab246c0ef5905dcd3636e6197c0c34482e95203c238c331a0f1086245c385aa250a1077f8df068a3bc62ff8af18127bbdc0460a9c30
|
@@ -13,7 +13,7 @@ namespace :commit_msg do
|
|
13
13
|
|
14
14
|
unless Githook::Util.expected_msg_format?(commit_msg)
|
15
15
|
puts "ERROR! commit failed, commit msg doesn't match the required format"
|
16
|
-
puts "expected msg format:
|
16
|
+
puts "expected msg format: #{Githook::Util::MSG_FORMAT}"
|
17
17
|
exit 1
|
18
18
|
end
|
19
19
|
end
|
@@ -1,28 +1,38 @@
|
|
1
|
-
desc '
|
2
|
-
task :
|
3
|
-
# setup 1, check whether has '.githook/hooks' and '.git' folder
|
1
|
+
desc 'Check where .githook folder exists'
|
2
|
+
task :check_githook_folder do
|
4
3
|
hooks_path = '.githook/hooks'
|
5
4
|
unless Dir.exists?(hooks_path)
|
6
5
|
puts "There isn't a .githook/hooks folder."
|
7
6
|
exit 1
|
8
7
|
end
|
8
|
+
end
|
9
9
|
|
10
|
-
|
10
|
+
desc 'Check where .git folder exists'
|
11
|
+
task :check_git_folder do
|
12
|
+
git_path = '.git/hooks'
|
11
13
|
unless Dir.exists?(git_path)
|
12
|
-
puts "There isn't a .git folder."
|
14
|
+
puts "There isn't a .git/hooks folder."
|
13
15
|
exit 1
|
14
16
|
end
|
17
|
+
end
|
18
|
+
|
19
|
+
#################################################################
|
20
|
+
|
21
|
+
desc 'Setup hooks'
|
22
|
+
task :setup => [:check_githook_folder, :check_git_folder] do
|
23
|
+
# setup 1, check whether has '.githook/hooks' and '.git' folder
|
24
|
+
# => [:check_githook_folder, :check_git_folder]
|
15
25
|
|
16
26
|
# setup 2, backup hooks
|
17
27
|
puts "Backup old hooks:"
|
18
28
|
Rake::Task[:backup].invoke
|
19
29
|
|
20
30
|
# setup 3, copy hooks to .git/hooks
|
21
|
-
FileUtils.cp_r(
|
31
|
+
FileUtils.cp_r('.githook/hooks', '.git')
|
22
32
|
end
|
23
33
|
|
24
34
|
desc 'Backup old hooks in .git/hooks'
|
25
|
-
task :backup do
|
35
|
+
task :backup => :check_git_folder do
|
26
36
|
has_backup = false
|
27
37
|
Dir.glob('.git/hooks/*').each do |path|
|
28
38
|
file_name = path.split('/').last
|
@@ -38,7 +48,7 @@ task :backup do
|
|
38
48
|
end
|
39
49
|
|
40
50
|
desc 'Clear backup hooks in .git/hooks'
|
41
|
-
task :clear_backup do
|
51
|
+
task :clear_backup => :check_git_folder do
|
42
52
|
backup = Dir.glob('.git/hooks/*.bak')
|
43
53
|
Githook::Util.interactive_delete_files(backup, 'backup hooks')
|
44
54
|
end
|
@@ -53,43 +63,50 @@ end
|
|
53
63
|
# Githook::Util.interactive_delete_files(hooks, 'hooks')
|
54
64
|
# end
|
55
65
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
66
|
+
# all hooks
|
67
|
+
# https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
|
68
|
+
# ALL_HOOKS = %w(
|
69
|
+
# pre_commit
|
70
|
+
# prepare_commit_msg
|
71
|
+
# commit_msg
|
72
|
+
# post_commit
|
73
|
+
# pre_rebase
|
74
|
+
# post_checkout
|
75
|
+
# post_merge
|
76
|
+
# pre_push
|
77
|
+
# applypatch_msg
|
78
|
+
# pre_applypatch
|
79
|
+
# post_applypatch
|
80
|
+
# pre_receive
|
81
|
+
# post_receive
|
82
|
+
# update
|
83
|
+
# post_update
|
84
|
+
# )
|
85
|
+
|
86
|
+
desc 'Disable hooks: [HOOKS=pre_commit,commit_msg] githook disable'
|
87
|
+
task :disable => :check_git_folder do
|
88
|
+
target_hooks = (ENV['HOOKS'] || '').split(',')
|
89
|
+
target_hooks = Githook::Util.all_hooks if target_hooks.empty?
|
74
90
|
|
75
|
-
desc 'Disable hooks: HOOKS=pre_commit,commit_msg githook disable'
|
76
|
-
task :disable do
|
77
|
-
target_hooks = (ENV['HOOKS'] || '').split(',') || ALL_HOOKS
|
78
91
|
target_hooks.each do |hook|
|
79
92
|
hook_path = File.join('.git/hooks', hook.gsub('_', '-'))
|
93
|
+
disable_path = hook_path + '.disable'
|
80
94
|
if File.file?(hook_path)
|
81
|
-
disable_path = hook_path + '.disable'
|
82
95
|
FileUtils.mv(hook_path, disable_path)
|
83
96
|
puts "Disable #{hook} hook."
|
97
|
+
elsif File.file?(disable_path)
|
98
|
+
puts "#{hook} is already disabled, skip."
|
84
99
|
else
|
85
100
|
puts "#{hook} hook doesn't exist, skip."
|
86
101
|
end
|
87
102
|
end
|
88
103
|
end
|
89
104
|
|
90
|
-
desc 'Enable hooks: HOOKS=pre_commit,commit_msg githook enable'
|
91
|
-
task :enable do
|
92
|
-
target_hooks = (ENV['HOOKS'] || '').split(',')
|
105
|
+
desc 'Enable hooks: [HOOKS=pre_commit,commit_msg] githook enable'
|
106
|
+
task :enable => :check_git_folder do
|
107
|
+
target_hooks = (ENV['HOOKS'] || '').split(',')
|
108
|
+
target_hooks = Githook::Util.all_hooks if target_hooks.empty?
|
109
|
+
|
93
110
|
target_hooks.each do |hook|
|
94
111
|
hook_path = File.join('.git/hooks', hook.gsub('_', '-'))
|
95
112
|
disable_path = hook_path + '.disable'
|
@@ -105,10 +122,11 @@ task :enable do
|
|
105
122
|
end
|
106
123
|
|
107
124
|
desc 'List all hooks'
|
108
|
-
task :list do
|
125
|
+
task :list => :check_git_folder do
|
109
126
|
enabled_hooks = []
|
110
127
|
disabled_hooks = []
|
111
|
-
|
128
|
+
all_hooks = Githook::Util.all_hooks
|
129
|
+
all_hooks.each do |hook|
|
112
130
|
hook_path = File.join('.git/hooks', hook.gsub('_', '-'))
|
113
131
|
disable_path = hook_path + '.disable'
|
114
132
|
if File.file?(hook_path)
|
data/lib/githook/util.rb
CHANGED
@@ -37,6 +37,25 @@ module Githook
|
|
37
37
|
|
38
38
|
#######################################################
|
39
39
|
|
40
|
+
# def self.enabled_hooks
|
41
|
+
# Dir.glob('.git/hooks/*')
|
42
|
+
# .map { |path| path.split('/').last }
|
43
|
+
# .reject { |name| name.include?('.') }
|
44
|
+
# .map { |name| name.gsub('-', '_') }
|
45
|
+
# end
|
46
|
+
|
47
|
+
# include enabled_hooks and disabled_hooks
|
48
|
+
def self.all_hooks
|
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
|
+
.uniq
|
54
|
+
.map { |name| name.gsub('-', '_') }
|
55
|
+
end
|
56
|
+
|
57
|
+
#######################################################
|
58
|
+
|
40
59
|
# check whether origin commit msg is empty
|
41
60
|
def self.commit_msg_empty?(commit_msg_file)
|
42
61
|
File.open(commit_msg_file, 'r') do |f|
|
@@ -91,7 +110,8 @@ module Githook
|
|
91
110
|
commit_msg
|
92
111
|
end
|
93
112
|
|
94
|
-
MSG_FORMAT_REG = /^(FEATURE|BUG|MISC|REFACTOR)(\s#\d+)* - ([A-Z].*)/
|
113
|
+
MSG_FORMAT_REG = /^(FEATURE|BUG|MISC|REFACTOR|WIP)(\s#\d+)* - ([A-Z].*)/
|
114
|
+
MSG_FORMAT = "FEAUTER|BUG|MISC|REFACTOR|WIP #issue_num - Content"
|
95
115
|
# check commit msg style
|
96
116
|
def self.expected_msg_format?(commit_msg)
|
97
117
|
commit_msg.start_with?('Merge branch') || MSG_FORMAT_REG.match(commit_msg)
|
data/lib/githook/version.rb
CHANGED