A little script that might be useful for Lua developers on SVN. Disallows committing any Lua files to the repo, unless they have a --BAD-- (dash, dash, BAD, dash, dash) inside somewhere. Gotta have perl and lua installed.
pre-commit:
#!/bin/sh REPOS="$1" TXN="$2" if /home/wowzygor/usr/svn/hooks/check_lua_precommit.pl "$REPOS" "$TXN"; then echo q # OK else exit 1 fi exit 0
check_lua_precommit.pl:
#!/usr/bin/perl my $repos = shift; my $txn = shift; if ($txn) { $ttxn = "-t $txn"; } print STDERR "\n========================\n\n"; my $errcode = 0; foreach my $line (`svnlook changed $ttxn "$repos"`) { chomp($line); if ($line !~ /^([AUD]).\s\s(.+)$/) { print STDERR "Can't parse [$line].\n"; exit(1); } else { my $action = $1; my $file = $2; chomp($file); #If path has trailing slash, then it is a folder and we want to skip folders if($file =~ /\/$/) { next; } if ($action =~ /[AU]/) { if ($file =~ /\.lua$/) { $err = `svnlook cat $ttxn "$repos" "$file" | luac -p - 2>&1`; if ($?) { $badtag = `svnlook cat $ttxn "$repos" "$file" | grep "\\--BAD--"`; if (!$badtag) { print STDERR ("*** ERROR PARSING $file:\n$err"); $errcode += 1; } else { print STDERR ("*** KNOWN --BAD-- $file:\n$err"); } } } } } } print STDERR "\n------------------------\n\n"; if ($errcode) { print STDERR "Committing bad Lua files is NOT allowed. If you really, really, really need to commit them, add \"--BAD--\" to them anywhere.\n" } print STDERR "\n========================\n\n"; exit $errcode;