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)
41 IO.popen(['git', 'diff-index', '--cached', '--name-status', against]) do |f|
42 f.readlines.each do |line|
43 status, file = line.strip.split("\t", 2)
44 # Has file been added or modified?
45 if ['A', 'M'].include?(status)
46 next unless file.start_with?("#{SUBSCRIPTIONS_ROOT}/")
47 if !is_valid_subscription_file?(file)
48 $stderr.puts "Désolé : #{file} n'a pas le bon format !"