Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Svn pre-commit hook to disallow svn:mergeinfo on non-root directories

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.

like image 525
Stuart Lange Avatar asked Jul 22 '10 04:07

Stuart Lange


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.

like image 175
pmod Avatar answered Oct 03 '22 23:10

pmod


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
like image 27
Christopher Oezbek Avatar answered Sep 30 '22 23:09

Christopher Oezbek