[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: Campbell Allan <campbell.allan_at_sword-ciboodle.com>
Date: Thu, 19 Aug 2010 10:27:49 +0100

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 lock.
> 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 and 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 file 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 auto-props:
http://svnbook.red-bean.com/nightly/en/svn-book.html#svn.advanced.confarea.opts.config

oh, and I can help with the pre-commit hook. Hopefully this works but the
logic around testing the property might not be correct. You can test it by
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 svnlooks. I
butchered my own pre-commit that is preventing commits of files in certain
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

NOTIFIED=
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

rm $TMPFILE

if [ ! -z "$NOTIFIED" ]; then
    exit 1
fi

# All checks passed, so allow the commit.
exit 0

-- 
__________________________________________________________________________________
Sword Ciboodle is the trading name of ciboodle Limited (a company 
registered in Scotland with registered number SC143434 and whose 
registered office is at India of Inchinnan, Renfrewshire, UK, 
PA4 9LH) which is part of the Sword Group of companies.
This email (and any attachments) is intended for the named
recipient(s) and is private and confidential. If it is not for you, 
please inform us and then delete it. If you are not the intended 
recipient(s), the use, disclosure, copying or distribution of any 
information contained within this email is prohibited. Messages to 
and from us may be monitored. If the content is not about the 
business of the Sword Group then the message is neither from nor 
sanctioned by us.
Internet communications are not secure. You should scan this
message and any attachments for viruses. Under no circumstances
do we accept liability for any loss or damage which may result from
your receipt of this email or any attachment.
__________________________________________________________________________________
Received on 2010-08-19 11:31:13 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.