pre-commit 0.1.16 → 0.1.17
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.
- data/README.md +1 -0
- data/lib/pre-commit/checks.rb +3 -1
- data/lib/pre-commit/checks/migration_check.rb +1 -1
- data/lib/pre-commit/checks/php_check.rb +74 -0
- metadata +33 -36
data/README.md
CHANGED
@@ -24,6 +24,7 @@ These are the available checks:
|
|
24
24
|
* js\_lint\_all (Runs JSLint on all staged JS files)
|
25
25
|
* js\_lint\_new (Runs JSLint on all new staged JS files)
|
26
26
|
* closure\_syntax\_check
|
27
|
+
* php (Runs php -l on all staged files)
|
27
28
|
|
28
29
|
To configure which checks you would like to run, simply set the `pre-commit.checks` git configuration setting.
|
29
30
|
|
data/lib/pre-commit/checks.rb
CHANGED
@@ -8,6 +8,7 @@ require 'pre-commit/checks/jslint_check'
|
|
8
8
|
require 'pre-commit/checks/jshint_check'
|
9
9
|
require 'pre-commit/checks/migration_check'
|
10
10
|
require 'pre-commit/checks/ci_check'
|
11
|
+
require 'pre-commit/checks/php_check'
|
11
12
|
|
12
13
|
class PreCommit
|
13
14
|
|
@@ -36,7 +37,8 @@ class PreCommit
|
|
36
37
|
:closure_syntax_check => ClosureSyntaxCheck,
|
37
38
|
:merge_conflict => MergeConflict,
|
38
39
|
:migrations => MigrationCheck.new,
|
39
|
-
:ci => CiCheck.new
|
40
|
+
:ci => CiCheck.new,
|
41
|
+
:php => PhpCheck.new
|
40
42
|
}
|
41
43
|
|
42
44
|
# Can not delete this method with out a deprecation strategy.
|
@@ -22,7 +22,7 @@ class PreCommit
|
|
22
22
|
@error_message = "It looks like you're adding a migration, but did not update the schema file"
|
23
23
|
@passed = false
|
24
24
|
elsif schema_change && !migration_present
|
25
|
-
@error_message = "You're trying to change the schema without adding a
|
25
|
+
@error_message = "You're trying to change the schema without adding a migration file"
|
26
26
|
@passed = false
|
27
27
|
else
|
28
28
|
@passed = true
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'pre-commit/base'
|
2
|
+
require 'pre-commit/utils'
|
3
|
+
|
4
|
+
class PreCommit
|
5
|
+
class PhpCheck
|
6
|
+
|
7
|
+
def files_to_check
|
8
|
+
Utils.staged_files('.').split(" ")
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
php_files = reject_non_php(files_to_check)
|
13
|
+
if should_run?(php_files)
|
14
|
+
run(php_files)
|
15
|
+
else
|
16
|
+
# pretend the check passed and move on
|
17
|
+
true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def check_name
|
22
|
+
"PHP Lint"
|
23
|
+
end
|
24
|
+
|
25
|
+
def run(php_files)
|
26
|
+
errors = []
|
27
|
+
|
28
|
+
php_files.each do |file|
|
29
|
+
error = run_check(file)
|
30
|
+
unless error.nil?
|
31
|
+
errors << display_error(error)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
if errors.empty?
|
36
|
+
true
|
37
|
+
else
|
38
|
+
$stderr.puts errors.join("\n")
|
39
|
+
$stderr.puts
|
40
|
+
$stderr.puts 'pre-commit: You can bypass this check using `git commit -n`'
|
41
|
+
$stderr.puts
|
42
|
+
false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def should_run?(php_files)
|
47
|
+
php_files.any?
|
48
|
+
end
|
49
|
+
|
50
|
+
def reject_non_php(staged_files)
|
51
|
+
staged_files.select { |f| f =~ /\.(php|engine|theme|install|inc|module|test)$/ }
|
52
|
+
end
|
53
|
+
|
54
|
+
def run_check(file)
|
55
|
+
# We force PHP to display errors otherwise they will likely end up in the
|
56
|
+
# error_log and not in stdout.
|
57
|
+
cmd = "php -d display_errors=1 -l #{file}"
|
58
|
+
result = %x[ #{cmd} ]
|
59
|
+
# Filter out the obvious note from PHP.
|
60
|
+
result = result.split($/).find_all {|line| line !~ /Errors/}.join($/)
|
61
|
+
# If PHP exited non-zero then there was a parse error.
|
62
|
+
if ($? != 0)
|
63
|
+
result
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Format an error line.
|
68
|
+
def display_error(error)
|
69
|
+
"pre-commit: #{check_name.upcase} #{error}"
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
metadata
CHANGED
@@ -1,37 +1,36 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: pre-commit
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.17
|
4
5
|
prerelease:
|
5
|
-
version: 0.1.16
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Shajith Chacko, Josh Lubaway
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-11-06 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: execjs
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2153774880 !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
24
22
|
type: :runtime
|
25
|
-
|
26
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2153774880
|
25
|
+
description: A git pre-commit hook written in ruby with a few more tricks up it's
|
26
|
+
sleeve
|
27
27
|
email: dontneedmoreemail@example.com
|
28
|
-
executables:
|
28
|
+
executables:
|
29
29
|
- pre-commit
|
30
30
|
extensions: []
|
31
|
-
|
32
|
-
extra_rdoc_files:
|
31
|
+
extra_rdoc_files:
|
33
32
|
- README.md
|
34
|
-
files:
|
33
|
+
files:
|
35
34
|
- lib/pre-commit/base.rb
|
36
35
|
- lib/pre-commit/checks/ci_check.rb
|
37
36
|
- lib/pre-commit/checks/console_log.rb
|
@@ -41,6 +40,7 @@ files:
|
|
41
40
|
- lib/pre-commit/checks/jslint_check.rb
|
42
41
|
- lib/pre-commit/checks/merge_conflict.rb
|
43
42
|
- lib/pre-commit/checks/migration_check.rb
|
43
|
+
- lib/pre-commit/checks/php_check.rb
|
44
44
|
- lib/pre-commit/checks/tabs.rb
|
45
45
|
- lib/pre-commit/checks.rb
|
46
46
|
- lib/pre-commit/runner.rb
|
@@ -57,31 +57,28 @@ files:
|
|
57
57
|
- bin/pre-commit
|
58
58
|
homepage: http://github.com/jish/pre-commit
|
59
59
|
licenses: []
|
60
|
-
|
61
60
|
post_install_message:
|
62
|
-
rdoc_options:
|
61
|
+
rdoc_options:
|
63
62
|
- --main
|
64
63
|
- README.md
|
65
|
-
require_paths:
|
64
|
+
require_paths:
|
66
65
|
- lib
|
67
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
67
|
none: false
|
69
|
-
requirements:
|
70
|
-
- -
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
version:
|
73
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
73
|
none: false
|
75
|
-
requirements:
|
76
|
-
- -
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
version:
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
79
78
|
requirements: []
|
80
|
-
|
81
79
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.8.
|
80
|
+
rubygems_version: 1.8.6
|
83
81
|
signing_key:
|
84
82
|
specification_version: 3
|
85
83
|
summary: A slightly better git pre-commit hook
|
86
84
|
test_files: []
|
87
|
-
|