9 SafeYAML::OPTIONS[:default_mode] = :safe
11 SUBSCRIPTIONS_ROOT = 'Membres'
13 if system('git rev-parse --quiet --verify HEAD >/dev/null')
16 # Initial commit: diff against an empty tree object
17 against = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
20 def is_valid_subscription?(content)
21 return false if content.length == 0
22 return false unless content.start_with?("---\n")
24 data = YAML.load(content)
29 ['name', 'email'].each do |key|
30 return false unless data.include?(key)
35 def is_valid_subscription_file?(file)
36 IO.popen(['git', 'show', ":#{file}"]) do |f|
37 is_valid_subscription?(f.read)
42 IO.popen(['git', 'diff-index', '--cached', '--name-status', against]) do |f|
43 f.readlines.each do |line|
44 status, file = line.strip.split("\t", 2)
45 # Has file been added or modified?
46 if ['A', 'M'].include?(status)
48 next unless file.start_with?("#{SUBSCRIPTIONS_ROOT}/")
49 if !is_valid_subscription_file?(file)
50 $stderr.puts "Désolé : #{file} n'a pas le bon format !"