-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit.dist
More file actions
46 lines (35 loc) · 939 Bytes
/
pre-commit.dist
File metadata and controls
46 lines (35 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/ruby
# https://www.ruby-forum.com/topic/122170#544763
git_files = `git diff --cached --name-only`.lines.map(&:chomp)
project_path = `git rev-parse --show-toplevel`.chomp
offending_lines = {}
def File.binary? name
open name do |f|
while (b=f.read(256)) do
return true if b[ "\0"]
end
end
false
end
success = true
git_files.each do |file|
if File.basename(file) =~ /(?<!blade\.)php$/
if File.absolute_path(file).start_with?("#{project_path}/Spec/")
output = `php #{project_path}/vendor/bin/phpcs --standard=#{project_path}/.phpcs/phpspec.ruleset.xml #{project_path}/#{file}`
else
output = `php #{project_path}/vendor/bin/phpcs --standard=PSR2 #{project_path}/#{file}`
end
if not $?.success?
puts output
success = false
end
end
end
if not success
exit 1
end
output = `php #{project_path}/vendor/bin/phpspec run`
if not $?.success?
puts output
exit 1
end