How to set a trigger to prevent commits to SVN with mergeinfo property?
I'd like to avoid creating svn mergeinfo property on anything but the root of branches. We have a trunk branch and some other branches.
Assuming I know absolutely no开发者_如何学Pythonthing about svn triggers, what steps do I need to follow to setup a pre-commit hook that prevents additions of mergeinfo properties to anything but the root of branches?
The trunk is located in the repository's base "/trunk", and all branches are in "/branches/foo"
Basically, you need to define a SVN pre-commit hook. First though, read about hooks in general.
You will likely want to start with copying the pre-commit.tmpl file to pre-commit
, and implement the logic in there.
You will likely want to examine the diff of the currently executing transaction for lines like: Added: svn:mergeinfo
Since the information about which file this was added for is on a different line, you may need a more complex processing tool than grep - perhaps a simple perl script.
When you determine that a transaction has an added property that you don't want, you can block the commit; or, if you are especially daring, you could try to modify the transaction and continue.
The following should work. Your repository already has the svn:mergeinfo on the trunk, so you never want anyone to add one again.
By the way, our actual hook also ensures that every commit is accompanied by a log message and also protects against the deletion of some of our important top level directories via repo browser.
@echo off
set logfile=%TEMP%\%2.txt
"c:\program files\subversion\svnlook" log -t %2 %1 > %logfile%
for /f "tokens=1,2*" %%i in (%logfile%) do (
if %%i==UU goto checkmergetracking
)
for /f "tokens=1,2*" %%i in (%logfile%) do (
if %%i==_U goto checkmergetracking
)
del %logfile%
exit 0
:checkmergetracking
"c:\program files\subversion\svnlook" diff -t %2 %1 > %logfile%
find "Added: svn:mergeinfo" %logfile%
if ERRORLEVEL 1 goto nomergeinfo
del %logfile%
echo "Addition of Merge Info Not Allowed" >&2
exit 1
:nomergeinfo
del %logfile%
exit 0
精彩评论