I would like to use a pre-commit hook that prevents developers from setting svn:mergeinfo on non-root directories. That is, I want to enforce that svn:mergeinfo can only be set on directories like "trunk" or "branches/branchName". Developers sometimes need to be "reminded" that it's not good practice to use a subdirectory of the root as a merge target (per the best practices listed here). Does anyone have such a hook script or know where I could find one? I am in a windows environment, so batch or powershell would be preferable, but anything would certainly be helpful.
-
Strictly curiosity - are you using Subversion 1.5 or 1.6? (I too have suffered at the hands of svn:mergeinfos on all sorts of directories/files due to merges to/from non-root directories, but on 1.5) – Joshua McKinnon Jul 23 '10 at 01:05
-
1We're on 1.6. The issues I'm having are not due to the old 1.5 bugs where the svn client set mergeinfo on everything in sight. Rather, the issues are due to "user error", where a user performs a merge using a non-root directory like "trunk/mySubProject" as a merge target, therefore setting merge info on that directory. This screws up subsequent merges, as I'm sure you're aware. – Stuart Lange Jul 23 '10 at 13:43
-
Indeed - thanks for the info. We are only recently on 1.6, so I haven't had time to observe how things changed. I need to address the same problem, though. +Favorite – Joshua McKinnon Jul 23 '10 at 14:22
-
Oh, this seems like it'd be quite helpful... – Charles Aug 01 '10 at 03:35
-
@StuartLange: It does not really screw up subsequent merges, because SVN takes this info into account. Where it really becomes difficult is when you as a human want to figure out what has been merged or not. – Christopher Oezbek Feb 14 '16 at 20:55
2 Answers
First of all, I'd recommend using perl or python to do the task, windows batch leaves much to be desired.
You can use some example script from http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/ to start from. For example, verify-po.py script checks file encodings and commit-access-control.pl.in checks whether author has permissions to commit. You'd probably employ svnlook diff in your script (as in the latter one) to get changed properties for directories and go through the corresponding paths whether they're branches or tags using regular expression.
Update
Found enforcer pre-commit hook script which seems to be what you're looking for.
What this script does is it uses svnlook to peek into the transaction is progress. As it sifts through the transaction, it calls out to a set of hooks which allow the repository administrator to examine what is going on and decide whether it is acceptable.
It contains several methods and verify_property_line_added() among them, since it's called for each line that is added to a property on a file.

- 10,450
- 1
- 37
- 50
-
Looks like this is going to be the most likely solution and thus the bounty winner, unless anyone else can come up with something. – Charles Aug 07 '10 at 01:33
-
By the way, after your question I began interested in svn hooks, and I am going to implement some (starting with forbidding commits with no log message), and probably will reach the checking properties on commit - then will put here an another update. – pmod Aug 07 '10 at 20:45
If you can CPAN on the server:
https://github.com/gnustavo/SVN-Hooks/blob/master/examples/check-mergeinfo.pl
If not (based on http://comments.gmane.org/gmane.comp.version-control.subversion.user/118969):
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
if !($SVNLOOK log -t "$TXN" "$REPOS" | grep -q '\[override] ';) then
# Get list of paths which have changed
TXN_PATHS=$($SVNLOOK changed -t "$TXN" "$REPOS")
# Filter those which are allowed: /trunk, /branches/*,...
TXN_PATHS=$(echo "$TXN_PATHS" | grep -Ev "^....(trunk/|branches/[^/]+/)$")
# Iterate over all paths, which are not allowed to have mergeinfo
while IFS= read -r TXN_PATH; do
ELEM_PATH=$(echo "$TXN_PATH" | cut -c 5-)
MERGEINFO=$($SVNLOOK propget "$REPOS" svn:mergeinfo -t "$TXN" "$ELEM_PATH" 2>/dev/null)
if [ ! "$MERGEINFO" = "" ]; then
echo " Cannot merge into directory that is not trunk or a branch:" >&2;
echo " $ELEM_PATH" >&2;
echo " Override by using [override]." >&2;
exit 1;
fi
done <<< "$TXN_PATHS"
# echo "Merge info check: OK"
fi

- 23,994
- 6
- 61
- 85