Source code file content
sources / blog-sources / subversion / hook-layout-validator.rb
Size: 3233 bytes, 1 line
# This pre-commit hook verifies the folder layout
# $HeadURL: http://svn.jyskebank.dk/repos/JB/TI/jb.itu.ti.subversion-tailoring/trunk/jb-scripts/hook-layout-validator.rb $
# $LastChangedRevision: 9788 $
#
# Written by Jesper Skov <jskov@jyskebank.dk>
# Copyright 2009 Jyske Bank
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This pre-commit hook verifies that the transaction follows the layout
# requirements, namely one of:
#
# REPO/DEPARTMENT/LOGICAL/branches/...
# REPO/DEPARTMENT/LOGICAL/tags/...
# REPO/DEPARTMENT/LOGICAL/trunk/...
require "optparse"
options = {}
ARGV.options do |opts|
opts.banner = "Usage: hook-layout-validator.rb [options]"
opts.on("-t=txn", "--txn=txn", "Transaction wanting to commit") do | txn |
options[:txn] = txn
end
opts.def_option("-r=repository", "--repository=repository", "Repository for commit") do | repository |
options[:repository] = repository
end
opts.on_tail("-h", "--help", "Show this message") do
puts(opts)
exit(0)
end
opts.parse!
end
if not (options[:txn] and options[:repository])
$stderr.puts("Must specify transaction and repository")
exit(1)
end
output=`svnlook.exe changed #{options[:repository]} --transaction #{options[:txn]} 2>&1`
res = $?
if res != 0
$stderr.puts("Failed to run svnlook")
$stderr.puts(output)
exit(1)
end
# Output is a list of changed files
# Go through list and ensure all files comply with the required layout
# Note that folders are postfixed with /
violations = ""
output.each_line { | l |
# Note that the order of matching is important!
path = l.split()[1]
case path
when /^(trunk|tags|branches)\//
violations += " #{path} (trunk/tags/branches reserved at department level)\n"
when /^[^\/]+\/(trunk|tags|branches)\/.*/
violations += " #{path} (trunk/tags/branches reserved at logical level)\n"
when /^[^\/]+\/[^\/]+\/(tags|branches)\/[^\/]+\/trunk\/.*/
violations += " #{path} (trunk below tags|branches symptom of retagging)\n"
when /^[^\/]+\/[^\/]+\/(trunk|tags|branches)\/.*/ # Manipulation of file/folder below trunk/tags/branches
next
when /^[^\/]+\/$/ # Creation of new department folder
next
when /^[^\/]+\/[^\/]+\/$/ # Creation of new logical folder
next
else
violations += " #{path}\n"
end
}
if not violations.empty?
$stderr.puts("-------")
$stderr.puts("The following violate the DEPARTMENT/LOGICAL/trunk|version|tags/... pattern")
$stderr.puts violations
exit(1)
end
exit(0)






