git の pre-commit を Rake で書く
良い大人は「Make で良いじゃん」とか言わない.
# Rakefile require 'rake/clean' makefiles=`find -name Makefile`.split `cat .gitignore`.split.each do |ign| makefiles.delete_if{|x| x =~/^\.\/#{ign}/} if FileTest.directory?(ign) end task :default => "distclean" desc "DistClean all project" task :distclean do MAKEFILES.each do |makefile| cd File.dirname(makefile) do if makefile =~/gste-dns/ sh "make" else sh "make clean" end end end end
無駄がありそうだけれど, まあ良いや. これを .git/hooks/pre-commit で呼ぶようにしておく.
#!/bin/sh RAKE=`which rake` if [[ ! -x $RAKE ]]; then echo "ERROR: rake is not found" exit 1 fi echo -n "rake clean ..." $RAKE -f 00Rakefile distclean 1>/dev/null 2>&1 echo "done"
こんなんで良いのかな?