source 'https://rubygems.org'
-gem 'cucumber'
-gem 'aruba'
-gem 'safe_yaml'
+gemspec
+PATH
+ remote: .
+ specs:
+ nos_oignons (0.0.1.dev)
+ safe_yaml
+
GEM
remote: https://rubygems.org/
specs:
DEPENDENCIES
aruba
cucumber
- safe_yaml
+ nos_oignons!
require 'bundler'
Bundler.setup
-require 'safe_yaml'
-SafeYAML::OPTIONS[:default_mode] = :safe
-
-SUBSCRIPTIONS_ROOT = 'Membres'
+require 'nos_oignons/git'
+require 'nos_oignons/subscriptions'
if system('git rev-parse --quiet --verify HEAD >/dev/null')
against = 'HEAD'
against = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
end
-def is_valid_subscription?(content)
- return false if content.length == 0
- return false unless content.start_with?("---\n")
- begin
- data = YAML.load(content)
- rescue ArgumentError
- # Parse error
- return false
- end
- ['name', 'email'].each do |key|
- return false unless data.include?(key)
- end
- true
-end
-
-def is_valid_subscription_file?(file)
- IO.popen(['git', 'show', ":#{file}"]) do |f|
- is_valid_subscription?(f.read)
- end
-end
-
-IO.popen(['git', 'diff-index', '--cached', '--name-status', against]) do |f|
- f.readlines.each do |line|
- status, file = line.strip.split("\t", 2)
- # Has file been added or modified?
- if ['A', 'M'].include?(status)
- next unless file.start_with?("#{SUBSCRIPTIONS_ROOT}/")
- if !is_valid_subscription_file?(file)
- $stderr.puts "Désolé : #{file} n'a pas le bon format !"
- exit 1
- end
+IO.popen(['git', 'diff-index', '--cached', '--name-status', against]) do |io|
+ handle_modified_files(io) do |file|
+ next unless file.start_with?("#{SUBSCRIPTIONS_ROOT}/")
+ # Use empty ref to get the index
+ if !is_valid_subscription_file?('', file)
+ $stderr.puts "Désolé : #{file} n'a pas le bon format !"
+ exit 1
end
end
end
-
--- /dev/null
+#!/usr/bin/ruby1.9.1
+#-*- coding: utf-8 -*-
+
+require 'rubygems'
+require 'bundler'
+Bundler.setup
+
+require 'nos_oignons/git'
+require 'nos_oignons/subscriptions'
+
+$stdin.readlines.each do |ref_line|
+ old_value, new_value, ref_name = ref_line.rstrip.split(' ', 3)
+ IO.popen(['git', 'diff', '--name-status', "#{old_value}..#{new_value}"]) do |io|
+ handle_modified_files(io) do |file|
+ next unless file.start_with?("#{SUBSCRIPTIONS_ROOT}/")
+ if !is_valid_subscription_file?(new_value, file)
+ $stderr.puts "Désolé : #{file} n'a pas le bon format !"
+ exit 1
+ end
+ end
+ end
+end
# Create main repository
create_dir 'main'
cd 'main'
- run_simple 'git init'
+ @main_repository_path = current_dir
+ run_simple 'git init --bare'
+ cd '..'
+
+ # Clone it now
+ run_simple 'git clone main clone'
+ cd 'clone'
create_dir 'Membres'
BASE_SUBSCRIPTIONS.each_pair do |number, data|
file = subscription_filename_for_id(number)
run_simple "git add #{file}"
end
run_simple 'git commit -m "Initial data set from fixtures"'
- cd '..'
-
- # Clone it now
- run_simple 'git clone main clone'
- cd 'clone'
+ run_simple 'git push origin master'
end
Given /^le « pre-commit hook » correctement configuré$/ do
"#{current_dir}/.git/hooks/pre-commit"
end
+Given /^le « pre-receive hook » configuré sur le dépôt principal$/ do
+ FileUtils.ln_s File.expand_path('../../../bin/pre-receive-hook', __FILE__),
+ "#{@main_repository_path}/hooks/pre-receive"
+end
+
When /je fais un `commit` du nouveau fichier$/ do
run_simple "git add #{@file}"
run_simple "git commit #{@file} -m 'new file'", false # do not fail on error
end
+
+When /^que je pousse la modification$/ do
+ run_simple "git add #{@file}"
+ run_simple "git commit #{@file} -m 'new file'"
+ run_simple 'git push origin master', false # do not fail on error
+end
--- /dev/null
+def handle_modified_files(io)
+ io.readlines.each do |line|
+ status, file = line.strip.split("\t", 2)
+ # Has file been added or modified?
+ if ['A', 'M'].include?(status)
+ yield file
+ end
+ end
+end
--- /dev/null
+require 'safe_yaml'
+SafeYAML::OPTIONS[:default_mode] = :safe
+
+SUBSCRIPTIONS_ROOT = 'Membres'
+
+def is_valid_subscription?(content)
+ return false if content.length == 0
+ return false unless content.start_with?("---\n")
+ begin
+ data = YAML.load(content)
+ rescue ArgumentError
+ # Parse error
+ return false
+ end
+ ['name', 'email'].each do |key|
+ return false unless data.include?(key)
+ end
+ true
+end
+
+def is_valid_subscription_file?(ref, file)
+ IO.popen(['git', 'show', "#{ref}:#{file}"]) do |f|
+ is_valid_subscription?(f.read)
+ end
+end
--- /dev/null
+Gem::Specification.new do |s|
+ s.name = 'nos_oignons'
+ s.version = '0.0.1.dev'
+ s.require_paths = ['lib']
+
+ s.add_development_dependency 'cucumber'
+ s.add_development_dependency 'aruba'
+ s.add_runtime_dependency 'safe_yaml'
+end