File tree 29 files changed +42
-41
lines changed
spec/overcommit/hook/pre_commit
29 files changed +42
-41
lines changed Original file line number Diff line number Diff line change 4
4
5
5
* Change ` command ` hook helper signature to accept an array of arguments
6
6
instead of a shell string
7
+ * Rename ` command ` hook helper to ` execute `
7
8
* Add support for JRuby 1.7.9 in Ruby 1.9 mode
8
9
9
10
## 0.6.3
Original file line number Diff line number Diff line change @@ -51,8 +51,8 @@ def in_path?(cmd)
51
51
Overcommit ::Utils . in_path? ( cmd )
52
52
end
53
53
54
- def command ( cmd )
55
- Overcommit ::Utils . command ( cmd )
54
+ def execute ( cmd )
55
+ Overcommit ::Utils . execute ( cmd )
56
56
end
57
57
58
58
# Gets a list of staged files that apply to this hook based on its
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ module Overcommit::Hook::CommitMsg
7
7
# edit the message after a prepare-commit-msg hook was run.
8
8
class GerritChangeId < Base
9
9
def run
10
- result = command ( [ SCRIPT_LOCATION , commit_message_file ] )
10
+ result = execute ( [ SCRIPT_LOCATION , commit_message_file ] )
11
11
return ( result . success? ? :good : :bad ) , result . stdout
12
12
end
13
13
Original file line number Diff line number Diff line change @@ -15,15 +15,15 @@ def run
15
15
private
16
16
17
17
def dependencies_changed?
18
- result = command ( %w[ git diff --exit-code --name-only ] + [ new_head , previous_head ] )
18
+ result = execute ( %w[ git diff --exit-code --name-only ] + [ new_head , previous_head ] )
19
19
20
20
result . stdout . split ( "\n " ) . any? do |file |
21
21
Array ( @config [ 'include' ] ) . any? { |glob | File . fnmatch ( glob , file ) }
22
22
end
23
23
end
24
24
25
25
def dependencies_satisfied?
26
- command ( %w[ bundle check ] ) . success?
26
+ execute ( %w[ bundle check ] ) . success?
27
27
end
28
28
end
29
29
end
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ module Overcommit::Hook::PreCommit
2
2
# Checks the format of an author's email address.
3
3
class AuthorEmail < Base
4
4
def run
5
- result = command ( %w[ git config --get user.email ] )
5
+ result = execute ( %w[ git config --get user.email ] )
6
6
email = result . stdout . chomp
7
7
8
8
unless email =~ /#{ @config [ 'pattern' ] } /
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ module Overcommit::Hook::PreCommit
2
2
# Ensures that a commit author has a name with at least first and last names.
3
3
class AuthorName < Base
4
4
def run
5
- result = command ( %w[ git config --get user.name ] )
5
+ result = execute ( %w[ git config --get user.name ] )
6
6
name = result . stdout . chomp
7
7
8
8
unless name . split ( ' ' ) . count >= 2
Original file line number Diff line number Diff line change @@ -8,14 +8,14 @@ def run
8
8
end
9
9
10
10
# Ignore if Gemfile.lock is not tracked by git
11
- return :good if command ( %w[ git check-ignore ] + [ LOCK_FILE ] ) . success?
11
+ return :good if execute ( %w[ git check-ignore ] + [ LOCK_FILE ] ) . success?
12
12
13
- result = command ( %w[ bundle check ] )
13
+ result = execute ( %w[ bundle check ] )
14
14
unless result . success?
15
15
return :bad , result . stdout
16
16
end
17
17
18
- result = command ( %w[ git diff --quiet -- ] + [ LOCK_FILE ] )
18
+ result = execute ( %w[ git diff --quiet -- ] + [ LOCK_FILE ] )
19
19
unless result . success?
20
20
return :bad , "#{ LOCK_FILE } is not up-to-date -- run `bundle check`"
21
21
end
Original file line number Diff line number Diff line change 6
6
return :warn , 'Run `npm install -g coffeelint`'
7
7
end
8
8
9
- result = command ( %w[ coffeelint --quiet ] + applicable_files )
9
+ result = execute ( %w[ coffeelint --quiet ] + applicable_files )
10
10
return :good if result . success?
11
11
return :bad , result . stdout
12
12
end
Original file line number Diff line number Diff line change 6
6
return :warn , 'csslint not installed -- run `npm install -g csslint`'
7
7
end
8
8
9
- result = command ( %w[ csslint --quiet --format=compact ] + applicable_files )
9
+ result = execute ( %w[ csslint --quiet --format=compact ] + applicable_files )
10
10
output = result . stdout
11
11
return ( output !~ /Error - (?!Unknown @ rule)/ ? :good : :bad ) , output
12
12
end
Original file line number Diff line number Diff line change 6
6
return :warn , 'haml-lint not installed -- run `gem install haml-lint`'
7
7
end
8
8
9
- result = command ( %w[ haml-lint ] + applicable_files )
9
+ result = execute ( %w[ haml-lint ] + applicable_files )
10
10
return :good if result . success?
11
11
12
12
# Keep lines from the output for files that we actually modified
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ module Overcommit::Hook::PreCommit
3
3
class HardTabs < Base
4
4
def run
5
5
# Catches hard tabs
6
- result = command ( %w[ grep -IHn ] + [ "\t " ] + applicable_files )
6
+ result = execute ( %w[ grep -IHn ] + [ "\t " ] + applicable_files )
7
7
unless result . stdout . empty?
8
8
return :bad , "Hard tabs detected:\n #{ result . stdout } "
9
9
end
Original file line number Diff line number Diff line change 6
6
return :warn , 'jshint not installed -- run `npm install -g jshint`'
7
7
end
8
8
9
- result = command ( %w[ jshint ] + applicable_files )
9
+ result = execute ( %w[ jshint ] + applicable_files )
10
10
output = result . stdout
11
11
12
12
return ( output . empty? ? :good : :bad ) , output
Original file line number Diff line number Diff line change 7
7
return :warn , 'jscs not installed -- run `npm install -g jscs`'
8
8
end
9
9
10
- result = command ( %w[ jscs --reporter=inline ] + applicable_files )
10
+ result = execute ( %w[ jscs --reporter=inline ] + applicable_files )
11
11
return :good if result . success?
12
12
13
13
if /Config.*not found/i =~ result . stderr
Original file line number Diff line number Diff line change 6
6
return :warn , 'flake8 not installed -- run `pip install flake8`'
7
7
end
8
8
9
- result = command ( %w[ flake8 ] + applicable_files )
9
+ result = execute ( %w[ flake8 ] + applicable_files )
10
10
11
11
return ( result . success? ? :good : :bad ) , result . stdout
12
12
end
Original file line number Diff line number Diff line change 6
6
return :warn , 'Rubocop not installed -- run `gem install rubocop`'
7
7
end
8
8
9
- result = command ( %w[ rubocop --format=emacs ] + applicable_files )
9
+ result = execute ( %w[ rubocop --format=emacs ] + applicable_files )
10
10
return :good if result . success?
11
11
12
12
output = result . stdout + result . stderr
Original file line number Diff line number Diff line change 6
6
return :warn , 'scss-lint not installed -- run `gem install scss-lint`'
7
7
end
8
8
9
- result = command ( %w[ scss-lint ] + applicable_files )
9
+ result = execute ( %w[ scss-lint ] + applicable_files )
10
10
return :good if result . success?
11
11
12
12
# Keep lines from the output for files that we actually modified
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ module Overcommit::Hook::PreCommit
2
2
# Checks for trailing whitespace in files.
3
3
class TrailingWhitespace < Base
4
4
def run
5
- result = command ( %w[ grep -IHn \s $ ] + applicable_files )
5
+ result = execute ( %w[ grep -IHn \s $ ] + applicable_files )
6
6
unless result . stdout . empty?
7
7
return :bad , "Trailing whitespace detected:\n #{ result . stdout } "
8
8
end
Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ def in_path?(cmd)
62
62
# Overcommit to call other Ruby executables without requiring that they be
63
63
# specified in Overcommit's Gemfile--a nasty consequence of using
64
64
# `bundle exec overcommit` while developing locally.
65
- def command ( args )
65
+ def execute ( args )
66
66
with_environment 'RUBYOPT' => nil do
67
67
Subprocess . spawn ( args )
68
68
end
Original file line number Diff line number Diff line change 8
8
9
9
before do
10
10
result . stub ( :stdout ) . and_return ( email )
11
- subject . stub ( :command ) . and_return ( result )
11
+ subject . stub ( :execute ) . and_return ( result )
12
12
end
13
13
14
14
context 'when user has no email' do
Original file line number Diff line number Diff line change 8
8
9
9
before do
10
10
result . stub ( :stdout ) . and_return ( name )
11
- subject . stub ( :command ) . and_return ( result )
11
+ subject . stub ( :execute ) . and_return ( result )
12
12
end
13
13
14
14
context 'when user has no name' do
Original file line number Diff line number Diff line change 37
37
38
38
before do
39
39
result . stub ( :success? => success , :stdout => 'Bundler error message' )
40
- subject . stub ( :command ) . and_call_original
41
- subject . stub ( :command ) . with ( %w[ bundle check ] ) . and_return ( result )
40
+ subject . stub ( :execute ) . and_call_original
41
+ subject . stub ( :execute ) . with ( %w[ bundle check ] ) . and_return ( result )
42
42
end
43
43
44
44
context 'and bundle check exits unsuccessfully' do
Original file line number Diff line number Diff line change 22
22
before do
23
23
result = double ( 'result' )
24
24
result . stub ( :success? ) . and_return ( true )
25
- subject . stub ( :command ) . and_return ( result )
25
+ subject . stub ( :execute ) . and_return ( result )
26
26
end
27
27
28
28
it { should pass }
33
33
result = double ( 'result' )
34
34
result . stub ( :success? ) . and_return ( false )
35
35
result . stub ( :stdout )
36
- subject . stub ( :command ) . and_return ( result )
36
+ subject . stub ( :execute ) . and_return ( result )
37
37
end
38
38
39
39
it { should fail_check }
Original file line number Diff line number Diff line change 22
22
before do
23
23
result = double ( 'result' )
24
24
result . stub ( :stdout ) . and_return ( '' )
25
- subject . stub ( :command ) . and_return ( result )
25
+ subject . stub ( :execute ) . and_return ( result )
26
26
end
27
27
28
28
it { should pass }
32
32
before do
33
33
result = double ( 'result' )
34
34
result . stub ( :stdout ) . and_return ( 'Error - @charset not allowed here' )
35
- subject . stub ( :command ) . and_return ( result )
35
+ subject . stub ( :execute ) . and_return ( result )
36
36
end
37
37
38
38
it { should fail_check }
Original file line number Diff line number Diff line change 22
22
before do
23
23
result = double ( 'result' )
24
24
result . stub ( :success? ) . and_return ( true )
25
- subject . stub ( :command ) . and_return ( result )
25
+ subject . stub ( :execute ) . and_return ( result )
26
26
end
27
27
28
28
it { should pass }
33
33
34
34
before do
35
35
result . stub ( :success? ) . and_return ( false )
36
- subject . stub ( :command ) . and_return ( result )
36
+ subject . stub ( :execute ) . and_return ( result )
37
37
end
38
38
39
39
context 'and it reports lines that were not modified by the commit' do
Original file line number Diff line number Diff line change 22
22
before do
23
23
result = double ( 'result' )
24
24
result . stub ( :stdout ) . and_return ( '' )
25
- subject . stub ( :command ) . and_return ( result )
25
+ subject . stub ( :execute ) . and_return ( result )
26
26
end
27
27
28
28
it { should pass }
32
32
before do
33
33
result = double ( 'result' )
34
34
result . stub ( :stdout ) . and_return ( 'Undefined variable' )
35
- subject . stub ( :command ) . and_return ( result )
35
+ subject . stub ( :execute ) . and_return ( result )
36
36
end
37
37
38
38
it { should fail_check }
Original file line number Diff line number Diff line change 23
23
result = double ( 'result' )
24
24
result . stub ( :success? => false ,
25
25
:stderr => 'Configuration file some-path/.jscs.json was not found.' )
26
- subject . stub ( :command ) . and_return ( result )
26
+ subject . stub ( :execute ) . and_return ( result )
27
27
end
28
28
29
29
it { should warn }
34
34
35
35
before do
36
36
result . stub ( :success? => false , :stderr => '' )
37
- subject . stub ( :command ) . and_return ( result )
37
+ subject . stub ( :execute ) . and_return ( result )
38
38
end
39
39
40
40
context 'and it reports lines that were not modified by the commit' do
Original file line number Diff line number Diff line change 23
23
result = double ( 'result' )
24
24
result . stub ( :success? ) . and_return ( true )
25
25
result . stub ( :stdout )
26
- subject . stub ( :command ) . and_return ( result )
26
+ subject . stub ( :execute ) . and_return ( result )
27
27
end
28
28
29
29
it { should pass }
34
34
result = double ( 'result' )
35
35
result . stub ( :success? ) . and_return ( false )
36
36
result . stub ( :stdout )
37
- subject . stub ( :command ) . and_return ( result )
37
+ subject . stub ( :execute ) . and_return ( result )
38
38
end
39
39
40
40
it { should fail_check }
Original file line number Diff line number Diff line change 22
22
before do
23
23
result = double ( 'result' )
24
24
result . stub ( :success? ) . and_return ( true )
25
- subject . stub ( :command ) . and_return ( result )
25
+ subject . stub ( :execute ) . and_return ( result )
26
26
end
27
27
28
28
it { should pass }
33
33
34
34
before do
35
35
result . stub ( :success? ) . and_return ( false )
36
- subject . stub ( :command ) . and_return ( result )
36
+ subject . stub ( :execute ) . and_return ( result )
37
37
end
38
38
39
39
context 'and it reports lines that were not modified by the commit' do
Original file line number Diff line number Diff line change 22
22
before do
23
23
result = double ( 'result' )
24
24
result . stub ( :success? ) . and_return ( true )
25
- subject . stub ( :command ) . and_return ( result )
25
+ subject . stub ( :execute ) . and_return ( result )
26
26
end
27
27
28
28
it { should pass }
33
33
34
34
before do
35
35
result . stub ( :success? ) . and_return ( false )
36
- subject . stub ( :command ) . and_return ( result )
36
+ subject . stub ( :execute ) . and_return ( result )
37
37
end
38
38
39
39
context 'and it reports lines that were not modified by the commit' do
You can’t perform that action at this time.
0 commit comments