git-hook 0.1.4 → 0.1.5
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 +14 -7
- data/lib/githook/templates/tasks/task.rake +1 -1
- data/lib/githook/util.rb +2 -2
- data/lib/githook/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf6166f0c4490566438f84355083fbb01137991d
|
4
|
+
data.tar.gz: df828c975fff03186afcf4b8db160baaa132c44d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9693c3c556aed7b16cdba1f46b1764aceada7cef9eba1a30dbb9e9cfe08abd60be5289e1264f2e1d94f83236417e5761353f7191ed1b7d1ddb57fca0c44820be
|
7
|
+
data.tar.gz: 1b86d49222d85ceb260d5561f025215c204b045df9b090b4a16608ad7afdec3da194380c7249180056f7cae4aca9cfd72f299e5cc2d4a69ae7e435a57ff043c6
|
data/README.md
CHANGED
@@ -71,7 +71,9 @@ Demos:
|
|
71
71
|
|
72
72
|
## Principle
|
73
73
|
|
74
|
-
Git will call some hooks when you commit, merge, rebase code, etc. The hooks place in `.git/hooks` folder, there are many default sample hooks, you need remove the `.sample`
|
74
|
+
Git will call some hooks when you commit, merge, rebase code, etc. The hooks place in `.git/hooks` folder, there are many default sample hooks, you need remove the `.sample` suffix to make it works if you want to execute the hook. The 3 hooks are most useful for us: `pre-commit`, `prepare-commit-msg`, `commit-msg`.
|
75
|
+
|
76
|
+
`pre-commit` hook will be executed at the most begining when commit code, `prepare-commit-msg` hook will be executed after `pre-commit` hook, before you start to input some commit message, `commit-msg` hook will be executed after you save the commit message.
|
75
77
|
|
76
78
|
[See more hooks introduction in git official website - Customizing Git - Git Hooks](https://git-scm.com/book/gr/v2/Customizing-Git-Git-Hooks).
|
77
79
|
|
@@ -117,7 +119,7 @@ Where do we define the `:pre_commit` value? It is defined by user in `.githook/c
|
|
117
119
|
# 'pre_commit:rubocop',
|
118
120
|
# 'pre_commit:rspec',
|
119
121
|
|
120
|
-
# uncomment following lines if it is
|
122
|
+
# uncomment following lines if it is an android or java project built by gradle
|
121
123
|
# 'pre_commit:checkstyle'
|
122
124
|
)
|
123
125
|
set :prepare_commit_msg, fetch(:prepare_commit_msg, []).push(
|
@@ -129,9 +131,9 @@ Where do we define the `:pre_commit` value? It is defined by user in `.githook/c
|
|
129
131
|
'commit_msg:check_msg'
|
130
132
|
)
|
131
133
|
|
132
|
-
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
|
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).
|
133
135
|
|
134
|
-
How the default tasks `pre_commit:rubocop` and `pre_commit:rspec`
|
136
|
+
How do the default tasks `pre_commit:rubocop` and `pre_commit:rspec` look like, they are defined in `tasks/pre-commit.rake`:
|
135
137
|
|
136
138
|
namespace :pre_commit do
|
137
139
|
desc 'check ruby code style by rubocop'
|
@@ -153,7 +155,7 @@ How the default tasks `pre_commit:rubocop` and `pre_commit:rspec` looks like, th
|
|
153
155
|
end
|
154
156
|
end
|
155
157
|
|
156
|
-
The `pre_commit:rubocop` just simply runs `bundle exec rubocop` command to check ruby code style, while `pre_commit:rspec` runs `bundle exec rspec` to test ruby code.
|
158
|
+
The `pre_commit:rubocop` just simply runs `bundle exec rubocop` command to check ruby code style, while `pre_commit:rspec` runs `bundle exec rspec` to test ruby code. (`pre_commit:checkstyle` runs the `./gradlew checkstyle` command.)
|
157
159
|
|
158
160
|
At last, let's see what do `prepare_commit_msg:prepare` and `commit_msg:check_msg` tasks do?
|
159
161
|
|
@@ -176,7 +178,7 @@ The `prepare_commit_msg:prepare` is defined in `tasks/prepare-commit-msg.rake`,
|
|
176
178
|
end
|
177
179
|
end
|
178
180
|
|
179
|
-
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
|
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.
|
180
182
|
|
181
183
|
namespace :commit_msg do
|
182
184
|
desc 'check commit msg style'
|
@@ -195,7 +197,7 @@ The `commit_msg:check_msg` is defined in `tasks/commit-msg.rake`, it is executed
|
|
195
197
|
|
196
198
|
The default `pre_commit:rubocp`, `pre_commit:rspec` tasks will help you check ruby code style and test ruby code before commit, the `prepare_commit_msg:prepare` task will help auto generate commit message according branch name when commit code, the `commit_msg:check_msg` task will help check commit message style after save the commit message.
|
197
199
|
|
198
|
-
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
|
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.
|
199
201
|
|
200
202
|
We can define it in any rake file in `.githook/tasks` folder, there is already an empty `task.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.
|
201
203
|
|
@@ -228,6 +230,11 @@ Demo:
|
|
228
230
|
|
229
231
|

|
230
232
|
|
233
|
+
## References
|
234
|
+
|
235
|
+
1. [Git Hooks Sample](https://github.com/baurine/git-hooks-sample)
|
236
|
+
1. [Step-by-Step Guide to Building Your First Ruby Gem](https://quickleft.com/blog/engineering-lunch-series-step-by-step-guide-to-building-your-first-ruby-gem/)
|
237
|
+
|
231
238
|
## License
|
232
239
|
|
233
240
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -12,7 +12,7 @@
|
|
12
12
|
# valid = %w(develop staging master).include?(branch_name)
|
13
13
|
# end
|
14
14
|
# unless valid
|
15
|
-
# puts "Branch name #{branch_name} doesn't match the expected foramt."
|
15
|
+
# puts "Branch name \"#{branch_name}\" doesn't match the expected foramt."
|
16
16
|
# exit 1
|
17
17
|
# end
|
18
18
|
# end
|
data/lib/githook/util.rb
CHANGED
@@ -127,8 +127,8 @@ module Githook
|
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
130
|
-
DEF_MSG_SUMMARY_REG = /^(FEATURE|BUG|MISC|REFACTOR
|
131
|
-
DEF_MSG_SUMMARY_FORMAT = "FEAUTER|BUG|MISC|REFACTOR
|
130
|
+
DEF_MSG_SUMMARY_REG = /^(FEATURE|BUG|MISC|REFACTOR)(\s#\d+)* - ([A-Z].*)[^.]$/
|
131
|
+
DEF_MSG_SUMMARY_FORMAT = "FEAUTER|BUG|MISC|REFACTOR #issue_num - Summary"
|
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)
|
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.5
|
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-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -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.13
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: Setup git hooks easily
|