Skip to content

Commit

Permalink
rajout color
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy MAURO committed Mar 18, 2013
1 parent 3bfa355 commit 28e855d
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions hooks/pre-commit
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@


# check for whitespace errors
RED=''
YELLOW=''
CYAN=''
GREEN=''
N=''

git_ws_check = `git diff-index --check --cached HEAD --`
unless $?.success?
puts git_ws_check
Expand All @@ -16,30 +22,33 @@ COOKBOOK_PATH = File.split `git rev-parse --show-toplevel`
PARENT_PATH = COOKBOOK_PATH[0]
COOKBOOK_NAME = COOKBOOK_PATH[1].chomp # remove trailing newline

puts 'Running knife cookbook test...'
knife_output = `knife cookbook test #{ COOKBOOK_NAME } -o #{ PARENT_PATH } -c ~/chef/wit/chef-repo/.chef/knife.rb`
puts '[ PRE-COMMIT ] Running knife cookbook test...'
knife_output = `knife cookbook test #{ COOKBOOK_NAME } -o #{ PARENT_PATH } | sed -e 's/.*/\t\t\t> &/g'`
unless $?.success?
puts knife_output
puts "[ PRE-COMMIT ] #{RED}FAIL#{N} #{knife_output}"
exit 1
end
puts "[ PRE-COMMIT ] #{GREEN}Passsed#{N} 'knife cookbook test'"

puts 'Running tailor...'

puts '[ PRE-COMMIT ] Running tailor...'
# Get the file names of (A)dded, (C)opied, (M)odified Ruby files
STAGED_FILES = `git diff-index --name-only --diff-filter=ACM HEAD -- '*.rb'`
STAGED_FILES.lines do |file|
file.chomp! # remove carriage returns
puts file
tailor_output = `tailor --max-line-length 999 #{ file }`
tailor_output = `tailor --max-line-length 999 #{ file } | sed -e 's/.*/\t\t\t> &/g'`
unless $?.success?
puts tailor_output
puts "[ PRE-COMMIT ] #{RED}FAIL#{N} 'tailor #{ file }'"
puts tailor_output
exit 1
end
puts "[ PRE-COMMIT ] #{GREEN}Passsed#{N} 'tailor #{ file }'"
end

puts "Running foodcritic..."
fc_output = `foodcritic --epic-fail any #{ File.join(PARENT_PATH, COOKBOOK_NAME) }`
puts "[ PRE-COMMIT ] Running foodcritic..."
fc_output = `foodcritic --epic-fail any #{ File.join(PARENT_PATH, COOKBOOK_NAME) } | sed -e 's/.*/\t\t\t> &/g' `
unless $?.success?
puts "[ PRE-COMMIT ] #{RED}FAIL#{N} 'foodcritic #{ File.join(PARENT_PATH, COOKBOOK_NAME) }'"
puts fc_output
exit 1
end
puts "[ PRE-COMMIT ] #{GREEN}Passed#{N} 'foodcritic #{ File.join(PARENT_PATH, COOKBOOK_NAME) }'"

0 comments on commit 28e855d

Please sign in to comment.