source: trunk/hooks/pre-lock.tmpl @ 1572

Last change on this file since 1572 was 1572, checked in by pg, 16 months ago
File size: 3.6 KB
Line 
1#!/bin/sh
2
3# PRE-LOCK HOOK
4#
5# The pre-lock hook is invoked before an exclusive lock is
6# created.  Subversion runs this hook by invoking a program
7# (script, executable, binary, etc.) named 'pre-lock' (for which
8# this file is a template), with the following ordered arguments:
9#
10#   [1] REPOS-PATH   (the path to this repository)
11#   [2] PATH         (the path in the repository about to be locked)
12#   [3] USER         (the user creating the lock)
13#   [4] COMMENT      (the comment of the lock)
14#   [5] STEAL-LOCK   (1 if the user is trying to steal the lock, else 0)
15#
16# If the hook program outputs anything on stdout, the output string will
17# be used as the lock token for this lock operation.  If you choose to use
18# this feature, you must guarantee the tokens generated are unique across
19# the repository each time.
20#
21# If the hook program exits with success, the lock is created; but
22# if it exits with failure (non-zero), the lock action is aborted
23# and STDERR is returned to the client.
24#
25# The default working directory for the invocation is undefined, so
26# the program should set one explicitly if it cares.
27#
28# On a Unix system, the normal procedure is to have 'pre-lock'
29# invoke other programs to do the real work, though it may do the
30# work itself too.
31#
32# Note that 'pre-lock' must be executable by the user(s) who will
33# invoke it (typically the user httpd runs as), and that user must
34# have filesystem-level permission to access the repository.
35#
36# On a Windows system, you should name the hook program
37# 'pre-lock.bat' or 'pre-lock.exe',
38# but the basic idea is the same.
39#
40# The hook program runs in an empty environment, unless the server is
41# explicitly configured otherwise.  For example, a common problem is for
42# the PATH environment variable to not be set to its usual value, so
43# that subprograms fail to launch unless invoked via absolute path.
44# If you're having unexpected problems with a hook program, the
45# culprit may be unusual (or missing) environment variables.
46#
47# CAUTION:
48# For security reasons, you MUST always properly quote arguments when
49# you use them, as those arguments could contain whitespace or other
50# problematic characters. Additionally, you should delimit the list
51# of options with "--" before passing the arguments, so malicious
52# clients cannot bootleg unexpected options to the commands your
53# script aims to execute.
54# For similar reasons, you should also add a trailing @ to URLs which
55# are passed to SVN commands accepting URLs with peg revisions.
56#
57# Here is an example hook script, for a Unix /bin/sh interpreter.
58# For more examples and pre-written hooks, see those in
59# the Subversion repository at
60# http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/ and
61# http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/
62
63
64REPOS="$1"
65PATH="$2"
66USER="$3"
67COMMENT="$4"
68STEAL="$5"
69
70# If a lock exists and is owned by a different person, don't allow it
71# to be stolen (e.g., with 'svn lock --force ...').
72
73# (Maybe this script could send email to the lock owner?)
74SVNLOOK=/usr/local/bin/svnlook
75GREP=/bin/grep
76SED=/bin/sed
77
78LOCK_OWNER=`$SVNLOOK lock "$REPOS" "$PATH" | \
79            $GREP '^Owner: ' | $SED 's/Owner: //'`
80
81# If we get no result from svnlook, there's no lock, allow the lock to
82# happen:
83if [ "$LOCK_OWNER" = "" ]; then
84  exit 0
85fi
86
87# If the person locking matches the lock's owner, allow the lock to
88# happen:
89if [ "$LOCK_OWNER" = "$USER" ]; then
90  exit 0
91fi
92
93# Otherwise, we've got an owner mismatch, so return failure:
94echo "Error: $PATH already locked by ${LOCK_OWNER}." 1>&2
95exit 1
Note: See TracBrowser for help on using the repository browser.