[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: any "must-have" hooks to implement on svn server?

From: Ryan Schmidt <subversion-2008c_at_ryandesign.com>
Date: Sun, 20 Jul 2008 00:58:22 -0500

On Jul 20, 2008, at 00:42, Waynn Lue wrote:

>>> There are files that should exist in each developer's environment
>>> called dbsecret.php.inc and reality.php.inc, and I want to make
>>> sure no one tries to check in a file named that. This was my
>>> attempt in pre-commit to fix it, but it doesn't seem to work.
>>> Any ideas?
>>>
>>> $SVNLOOK changed -t "$TXN" "$REPOS" | \
>>> grep -E "dbsecret.php.inc|reality.php.inc" > /dev/null || exit 1
>>
>> You're telling the script to exit if the filename is NOT
>> dbsecret.php.inc or reality.php.inc, when actually you want the
>> script to exit if the filename IS dbsecret.php.inc or
>> reality.php.inc. Change "||" to "&&" to fix this.
>>
>> But you should also escape the special characters in the filenames
>> (in this case the periods) and anchor the search to the beginning
>> and end of the string (so you don't match files whose names merely
>> CONTAIN dbsecret.php.inc or reality.php.inc). And you will
>> probably want to print message to the user explaining what went
>> wrong.
>>
>> $SVNLOOK changed -t "$TXN" "$REPOS" | \
>> grep -E "^....(.*/)?(dbsecret\.php\.inc|reality\.php\.inc)
>> $" > /dev/null
>> if [ $? -eq 0 ]; then
>> echo "You con't commit files named dbsecret.php.inc or
>> reality.php.inc" 1>&2
>> exit 1
>> fi
>> exit 0
>
> Excellent, thanks so much for the help, this worked like a charm.
> Two quick questions so I understand what's going on, why the "...."
> at the beginning of the regex? Shouldn't (.*/) be enough? Second,
> what's $? map to? Searching "$? bash" didn't help.

"^...." matches 4 characters at the beginning of the string. The
format of "svnlook changed" is such that the first character
indicates whether the file or directory contents are Added, Modified
or Deleted; the second character indicates whether the properties are
being Modified; and the third and fourth characters are I believe
currently always blank. In any case I want to skip over those and get
to the path. "(.*/)?" matches, optionally, any path component. This
is because e.g. I want to find the string "dbsecret.php.inc" either
at the beginning of the path (meaning the file is at the root of the
repository) or after a "/" in the path (meaning it's in some
directory). I do not want to match a file named e.g.
"notdbsecret.php.inc". The "$" at the end of the regexp anchors it to
the end of the string, because I do not want to match a file named
e.g. "dbsecret.php.inc.txt". If you do want to match any file whose
name merely BEGINS with "dbsecret.php.inc" then remove the "$" at the
end of the regexp.

"$?" is the exit code of the previous command. So I'm checking if the
exit code of the grep command is 0 (meaning grep encountered no error
and did match the string).

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_subversion.tigris.org
For additional commands, e-mail: users-help_at_subversion.tigris.org
Received on 2008-07-20 07:59:02 CEST

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.