I Wrote a pre-commit hook script for SVN which running on Windows (.bat
).
The main purposes are:
- checking the reversion log length;
- prevent normal users deleting
[repo]/trunk/
folder; - prevent normal users deleting
[repo]/trunk/xxx/
folders;
But SVN always says:
command syntax not correct (exitcode 255)
The code is here:
@echo off
:: Stops commits that have empty log messages.
@echo off
setlocal
set REPOS=%1
set TXN=%2
Rem Check log length.
svnlook log -t "%TXN%" "%REPOS%" | findstr ".........." > nul
if %errorlevel% gtr 0 goto NoLog
@echo off
set Drop=No
Rem Check Delete operation on trunk
svnlook changed -t "%TXN%" "%Repos%" | findstr "^D[ ]*trunk//$"
if %ERRORLEVEL% == 0 (set Drop=Yes)
Rem Check Delete operation on subdirectory of Trunk
svnlook changed -t "%TXN%" "%Repos%" | findstr "^D[ ]*trunk/[.]*//$"
if %ERRORLEVEL% == 0 (set Drop=Yes)
if Drop == Yes
(goto DropTrunk)
else
(exit 0)
:NoLog
echo You must inpu reversion log, and not less than 10 characters! 1>&2
exit 1
:DropTrunk
echo Only admin can delete the trunk directory and its subdirectory! 1>&2
exit 1