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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e07e1353c42ad407566f44a3cc3339ca748f70d
4
- data.tar.gz: fd51f0a58982531b6109b4816fecd8839a3cd4fe
3
+ metadata.gz: 134a66f85a7fbcb6e4d5edbb6be43b7aaa210c75
4
+ data.tar.gz: 7dd95a4d4f3d174146ae10f718844663e422bc1c
5
5
  SHA512:
6
- metadata.gz: b24efcfec922f5d3053b1761f2f8a40874f875429f43fa52bbe9f9509ac6b121c24bd039a054abefd69eefa5e4fab7e219a8428157ad4b7f7a8dd09fce14e6a7
7
- data.tar.gz: d6b4df7bba7a3f3d2faeb7df0bf660b0157548352e1c806e466cb6d87de6978fd1b4ea60f9dcb3645553bba18cc79ac6747696f68bc49f9ab9ff74e713529b71
6
+ metadata.gz: 7396e5185a8e6c14e55b1ef9c661e303f73fc17301ae4e4734a9dd63891143c1113934d3eb9c7ff7979b69860df345ab06fcfc479cb8c9f146edb36b7e3b694e
7
+ data.tar.gz: 1595ef10574f31d95ee5d09057cac9792a7d97db2d9035e6f254c755cce0b6088419b6fad0dae70696d4c52685a2c56d43b3e3c8f1248372086f214406215446
data/CHANGELOG CHANGED
@@ -1,9 +1,3 @@
1
- 0.2.1
2
-
3
- * Change Exceptions::MissingHook message
4
- * Add trailing_whitespace on readme and yaml example
5
- * Fix undefined method `git_repository'
6
-
7
1
  0.2.0
8
2
 
9
3
  * Add whitespace validation (by @rranelli)
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 languages.
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 only some simple hooks to:
43
+ By now you will find the following built-in hooks:
41
44
 
42
- - Prevent commit on master.
43
- - Prevent commit with rubocop offences.
44
- - Prevent commit with broken rspec tests.
45
- - Prevent commit with debugger
46
- - Prevent trailing whitespace
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 on your application
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
- This will force `git_hooks` installation before your application start.
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
@@ -23,6 +23,7 @@ module GitHooks
23
23
 
24
24
  def execute_pre_commits
25
25
  configurations.pre_commits.each do |pre_commit|
26
+ puts "Executing #{pre_commit}"
26
27
  GitHooks::PreCommit.const_get(pre_commit).validate
27
28
  end
28
29
  end
@@ -12,23 +12,31 @@ module GitHooks
12
12
  end
13
13
 
14
14
  def validate
15
- abort 'Prevented to commit with debugger' if any_debugger?
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 any_debugger?
21
- git_repository.added_or_modified.any? do |file_name|
22
- File.read(file_name) =~ debugger_regex
23
- end
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 'Check presence of trailling space' if offences?
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 offences?
31
- trailing_whitespace_validator.errors?(changed_files)
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
@@ -1,3 +1,3 @@
1
1
  module GitHooks
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -36,6 +36,12 @@ module GitHooks
36
36
 
37
37
  it { is_expected.to raise_error(SystemExit) }
38
38
  end
39
+
40
+ context 'when the modified file is not a ruby code file' do
41
+ let(:files) { ['some_text_file.txt'] }
42
+
43
+ it { is_expected.not_to raise_error }
44
+ end
39
45
  end
40
46
  end
41
47
 
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.2.1
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: 2014-09-04 00:00:00.000000000 Z
11
+ date: 2015-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop