git-hooks 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +0 -6
- data/README.md +17 -13
- data/lib/git-hooks.rb +1 -0
- data/lib/git_hooks/pre_commit/prevent_debugger.rb +17 -9
- data/lib/git_hooks/pre_commit/trailing_whitespace.rb +7 -5
- data/lib/git_hooks/version.rb +1 -1
- data/spec/git_hooks/pre_commit/prevent_debugger_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 134a66f85a7fbcb6e4d5edbb6be43b7aaa210c75
|
4
|
+
data.tar.gz: 7dd95a4d4f3d174146ae10f718844663e422bc1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7396e5185a8e6c14e55b1ef9c661e303f73fc17301ae4e4734a9dd63891143c1113934d3eb9c7ff7979b69860df345ab06fcfc479cb8c9f146edb36b7e3b694e
|
7
|
+
data.tar.gz: 1595ef10574f31d95ee5d09057cac9792a7d97db2d9035e6f254c755cce0b6088419b6fad0dae70696d4c52685a2c56d43b3e3c8f1248372086f214406215446
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -6,11 +6,12 @@
|
|
6
6
|
|
7
7
|
# GitHooks
|
8
8
|
|
9
|
-
Some usefull git hooks, it's written on ruby but can be used for other
|
9
|
+
Some usefull git hooks, it's written on ruby but can be used for other
|
10
|
+
languages.
|
10
11
|
|
11
12
|
## Installation
|
12
13
|
|
13
|
-
Add this line to your application's Gemfile
|
14
|
+
Add this line to your application's `Gemfile`:
|
14
15
|
|
15
16
|
gem 'git-hooks'
|
16
17
|
|
@@ -23,9 +24,10 @@ Or install it yourself as:
|
|
23
24
|
$ gem install git-hooks
|
24
25
|
|
25
26
|
## Usage
|
26
|
-
### Install git_hooks on project.
|
27
|
+
### Install git_hooks on your project.
|
27
28
|
|
28
29
|
```bash
|
30
|
+
$ cd /path/to/project
|
29
31
|
$ git_hooks install pre-commit [--force]
|
30
32
|
```
|
31
33
|
|
@@ -34,28 +36,30 @@ $ git_hooks install pre-commit [--force]
|
|
34
36
|
Create a `.git_hooks.yml` on project root.
|
35
37
|
|
36
38
|
```bash
|
39
|
+
$ cd /path/to/project
|
37
40
|
$ git_hooks init
|
38
41
|
```
|
39
42
|
|
40
|
-
By now you will find
|
43
|
+
By now you will find the following built-in hooks:
|
41
44
|
|
42
|
-
- Prevent
|
43
|
-
- Prevent
|
44
|
-
- Prevent
|
45
|
-
- Prevent
|
46
|
-
- Prevent trailing
|
45
|
+
- Prevent commits on master branch.
|
46
|
+
- Prevent commits with rubocop offenses.
|
47
|
+
- Prevent commits with broken rspec tests.
|
48
|
+
- Prevent commits with debugger.
|
49
|
+
- Prevent commits with trailing white space.
|
47
50
|
|
48
51
|
### Ensure hooks existence
|
49
52
|
|
50
|
-
To ensure that hooks exists on `.git/hooks`, include
|
51
|
-
start up (probably `config/environments/development.rb` or
|
52
|
-
`config/environments/test.rb`)
|
53
|
+
To ensure that hooks exists on `.git/hooks`, include this line
|
53
54
|
|
54
55
|
```ruby
|
55
56
|
GitHooks.validate_hooks!
|
56
57
|
```
|
57
58
|
|
58
|
-
|
59
|
+
on your application's start up (e.g. `config/environments/development.rb` or
|
60
|
+
`config/environments/test.rb` for a rails app).
|
61
|
+
|
62
|
+
This will force `git_hooks` installation before your application's start.
|
59
63
|
|
60
64
|
## Contributing
|
61
65
|
|
data/lib/git-hooks.rb
CHANGED
@@ -12,23 +12,31 @@ module GitHooks
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def validate
|
15
|
-
abort
|
15
|
+
abort(
|
16
|
+
"Prevented commit with debugger in #{files_with_debugger}"
|
17
|
+
) if files_with_debugger.any?
|
16
18
|
end
|
17
19
|
|
18
20
|
private
|
19
21
|
|
20
|
-
def
|
21
|
-
git_repository
|
22
|
-
|
23
|
-
|
22
|
+
def files_with_debugger
|
23
|
+
git_repository
|
24
|
+
.added_or_modified
|
25
|
+
.select(&ruby_files)
|
26
|
+
.select(&contains_debugger?)
|
27
|
+
end
|
28
|
+
|
29
|
+
def ruby_files
|
30
|
+
-> (file) { File.extname(file) == '.rb' }
|
31
|
+
end
|
32
|
+
|
33
|
+
def contains_debugger?
|
34
|
+
-> (file) { File.read(file) =~ debugger_regex }
|
24
35
|
end
|
25
36
|
|
26
37
|
def debugger_regex
|
27
38
|
Regexp.union(
|
28
|
-
%w(
|
29
|
-
binding.pry binding.remote_pry
|
30
|
-
save_and_open_page debugger
|
31
|
-
)
|
39
|
+
%w(binding.pry binding.remote_pry save_and_open_page debugger)
|
32
40
|
)
|
33
41
|
end
|
34
42
|
end
|
@@ -16,19 +16,21 @@ module GitHooks
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def validate
|
19
|
-
abort
|
19
|
+
abort(
|
20
|
+
"Prevented commit with trailing whitespace in files #{offenses}"
|
21
|
+
) if offenses.any?
|
20
22
|
end
|
21
23
|
|
22
|
-
private
|
23
|
-
|
24
24
|
def changed_files
|
25
25
|
git_repository
|
26
26
|
.added_or_modified
|
27
27
|
.select { |file| File.extname(file) == '.rb' }
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
31
|
-
|
30
|
+
def offenses
|
31
|
+
changed_files.map do |file|
|
32
|
+
trailing_whitespace_validator.errors?([file])
|
33
|
+
end
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
data/lib/git_hooks/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-hooks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael da Silva Almeida
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|