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

RE: pre-commit hook

From: Kenneth P. Turvey <kt-usenet_at_squeakydolphin.com>
Date: 2006-02-27 06:32:25 CET

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, 27 Feb 2006 00:20:55 -0500, Rob van Oostrum wrote:

> Where are you looking for the echo? The echo will not show up
> client-side because the script is called by the server process.
>
> Information about your OS etc would help. Also, could you provide shell
> output. For example, 'ls -l' on the hooks dir, as well as the contents
> of your pre-commit script.

I'm running Linux. There isn't any server. I'm running against a local
repository. The URL I'm using is:

file:///home/kt/subversion/WhateverDirectory

This is really just experimental. Please don't spend much time on it.

The hooks directory looks like this:

kt@volkswagon:~/subversion/hooks$ ls -l *
- -rwxr-x--- 1 kt kt 1993 2006-02-05 23:00 post-commit.tmpl
- -rwxr-x--- 1 kt kt 1648 2006-02-05 23:00 post-lock.tmpl
- -rwxr-x--- 1 kt kt 2287 2006-02-05 23:00 post-revprop-change.tmpl
- -rwxr-x--- 1 kt kt 1575 2006-02-05 23:00 post-unlock.tmpl
- -rwxr-xr-x 1 kt kt 1599 2006-02-26 23:05 pre-commit
- -rwxr-x--- 1 kt kt 2966 2006-02-05 23:00 pre-commit.tmpl
- -rwxr-x--- 1 kt kt 2009 2006-02-05 23:00 pre-lock.tmpl
- -rwxr-x--- 1 kt kt 2763 2006-02-05 23:00 pre-revprop-change.tmpl
- -rwxr-x--- 1 kt kt 1988 2006-02-05 23:00 pre-unlock.tmpl
- -rwxr-x--- 1 kt kt 2136 2006-02-05 23:00 start-commit.tmpl
kt@volkswagon:~/subversion/hooks$

The script is unchanged from an archive of one of the subversion mailing
lists and is intended to prevent commits to the tags directory.

#!/bin/sh
########################
# repository
########################
REPOS="$1"
# Transaction
TXN="$2"
########################
#debug
########################
#transaction=`$SVNLOOK changed -t $TXN $REPO`
#echo "$transaction";
echo This should be printed out
##########################
# user 'god' can do anything
##########################
# User=`svnlook author -t $TXN $REPOS`
# if ( $User == "god" ){ exit 0 }
#################################
# Log message contains some text.
#################################
SVNLOOK=/usr/bin/svnlook
$SVNLOOK log -t "$TXN" "$REPOS" | \
   grep "[a-zA-Z0-9]" > /dev/null || exit 1
########################
# Protect tags directory
########################
# Deny transaction if any line writes to tags directory that exists.
# tags dir match pattern
TAGS_REGEX='tags/[^/]\+'
# Get list of transactions in the 'tag' directory
TAGS_CHANGES=`"$SVNLOOK" changed -t "$TXN" "$REPOS" 2>/dev/null | \
                 awk '{ print $2; }' 2>/dev/null | \
                 grep ^tags/ 2>/dev/null | \
                 sed -e "s!^\($TAGS_REGEX\).*!\1!" | \
                 sort | \
                 uniq`
# Get head revision number
YOUNGEST=`svnlook youngest "$REPOS" 2>/dev/null`
# For every line in transaction,
# check to see if directory in tags exists
for CHANGE in $TAGS_CHANGES; do
  # If directory in tags exists, deny transaction
  if svnlook proplist -r $YOUNGEST "$REPOS" "$CHANGE" >/dev/null 2>&1 ;
then
    echo "Cannot modify existing tag: ${tag}" >&2
    exit 1
  fi
done
#######################
# Allow transaction
#######################
exit 0

Thank you,

- --
Kenneth P. Turvey <kt-usenet@squeakydolphin.com>
Phone : (314) 255-2199

XMPP IM: kpturvey@jabber.org
Yahoo IM: kpturvey2
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFEAo7hi2ZgbrTULjoRAhkrAJ9YKZBwKgK2yuVZMjZSh5h2/Nn2JQCaA1CC
ScOV8DLpuWzzRHYnKuGsl40=
=nmnJ
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Mon Feb 27 06:33:33 2006

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.