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

Re: Post commit script examples?

From: Greg Alexander <greg_at_alexanderzone.com>
Date: Thu, 19 Aug 2010 09:28:14 -0600

    Thanks for your reply. While I am not certain that my approach is the
best, I also know that a pre-commit hook will not suffice. What I am
looking to do is to setup a way so that all files in the repository require
a lock to be owned by the user before it can be committed the next time. I
also want this to be an automatically set property on any new files. I have
users used TortiseSVN, some SVN program for Mac (really not sure), and a
few accessing the repository command line. Trying to distribute something
to all of them may or may not be adopted and we really need this to be a
hard and fast rule. We have a situation today where we have many files and
many editors of that code and we have people stepping all over each other.
What I would really like is a way to have SVN set a lock as soon as a
working copy is created, but I don't think that can be done. To me some
sort of autolocking solution would be ideal as then it would be clear who
was working in what. However, I can't seem to find any case where that can
or has been done. Any help or pointers anyone can lend would be greatly


On Thu, 19 Aug 2010 10:27:49 +0100, Campbell Allan
<campbell.allan_at_sword-ciboodle.com> wrote:
> On Wednesday 18 Aug 2010, Greg Alexander wrote:
>> Hello,
>> I am a very new Subversion user and am trying to get a post commit
>> hook
>> script working. My Subversion is running on linux. The script I want to
>> add
>> would add the needs-lock property to every file that didn't have a
>> Any pointers on this would be great. I have searched and not found any
>> good, working, examples on how to do this. Thanks,
>> Greg
> Sorry for not answering your actual question but I feel that isn't the
> correct
> way to tackle the problem. Making changes to the repository during a
> post-commit means the committers working copy is instantly out of date
> is
> not a recommended way to work as it can also lead to an infinite loop as
> the
> change it makes triggers the script again.
> I think a better way to approach the problem would be to distribute an
> appropriate configuration file to the clients and implement a pre-commit
> hook
> to reject any commits without the properties. The config file on the
> client
> should have auto-props enabled (which is not the default) and have the
> needs
> lock added for all files. I've never tried adding a property on every
> so
> I'm not sure what to put in for the pattern, would * work?
> The area to look at in the subversion book is here, search for
> oh, and I can help with the pre-commit hook. Hopefully this works but
> logic around testing the property might not be correct. You can test it
> calling it directly (make sure it is executable) with the path to the
> repository and a revision number so long as you change the -t $TXN to -r

> $TXN. You could also put an exit 1 at the end of the script and place it
> in a
> test repository until it works the way you want it to. The exit 1 at the
> end
> will refuse all commits and saves on having to keep creating test files
> also I think the script can be cleaned up so their are only two
> I
> butchered my own pre-commit that is preventing commits of files in
> locations that didn't have the looped svnlook lookup.
> #!/bin/sh
> REPOS="$1"
> TXN="$2"
> SVNLOOK=/path/to/svnlook
> # redirect all stdout to stderr, this is passed back to the subversion
> client
> exec 1>&2
> TMPFILE=/tmp/svn-pre-commit-$$.tmp
> # pick out interesting files
> $SVNLOOK changed -t "$TXN" "$REPOS" | \
> perl -n -e 'print "$1\n" if /^A.* +(.*)$/;' > $TMPFILE
> exec 3<$TMPFILE
> while read -u 3 FILENAME ; do
> # check file
> PROPVALUE=$($SVNLOOK propget $REPOS -t $TXN svn:needs-lock $FILENAME

> 2>/dev/null)
> if [ -z "$PROPVALUE" ]; then
> if [ -z "$NOTIFIED" ]; then
> echo
> echo "Files need svn:needs-lock property set, use appropriate
> config
> file"
> echo
> NOTIFIED="yes"
> fi
> fi
> echo "$FILENAME"
> done
> if [ ! -z "$NOTIFIED" ]; then
> exit 1
> fi
> # All checks passed, so allow the commit.
> exit 0
Received on 2010-08-19 17:29:10 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.