1 |
2102
|
Luisehahne
|
#!/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 |
|
|
# The default working directory for the invocation is undefined, so
|
22 |
|
|
# the program should set one explicitly if it cares.
|
23 |
|
|
#
|
24 |
|
|
# If the hook program exits with success, the lock is created; but
|
25 |
|
|
# if it exits with failure (non-zero), the lock action is aborted
|
26 |
|
|
# and STDERR is returned to the client.
|
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 |
|
|
# Here is an example hook script, for a Unix /bin/sh interpreter:
|
41 |
|
|
|
42 |
|
|
REPOS="$1"
|
43 |
|
|
PATH="$2"
|
44 |
|
|
USER="$3"
|
45 |
|
|
COMMENT="$4"
|
46 |
|
|
STEAL="$5"
|
47 |
|
|
|
48 |
|
|
# If a lock exists and is owned by a different person, don't allow it
|
49 |
|
|
# to be stolen (e.g., with 'svn lock --force ...').
|
50 |
|
|
|
51 |
|
|
# (Maybe this script could send email to the lock owner?)
|
52 |
|
|
SVNLOOK=/usr/local/bin/svnlook
|
53 |
|
|
GREP=/bin/grep
|
54 |
|
|
SED=/bin/sed
|
55 |
|
|
|
56 |
|
|
LOCK_OWNER=`$SVNLOOK lock "$REPOS" "$PATH" | \
|
57 |
|
|
$GREP '^Owner: ' | $SED 's/Owner: //'`
|
58 |
|
|
|
59 |
|
|
# If we get no result from svnlook, there's no lock, allow the lock to
|
60 |
|
|
# happen:
|
61 |
|
|
if [ "$LOCK_OWNER" = "" ]; then
|
62 |
|
|
exit 0
|
63 |
|
|
fi
|
64 |
|
|
|
65 |
|
|
# If the person locking matches the lock's owner, allow the lock to
|
66 |
|
|
# happen:
|
67 |
|
|
if [ "$LOCK_OWNER" = "$USER" ]; then
|
68 |
|
|
exit 0
|
69 |
|
|
fi
|
70 |
|
|
|
71 |
|
|
# Otherwise, we've got an owner mismatch, so return failure:
|
72 |
|
|
echo "Error: $PATH already locked by ${LOCK_OWNER}." 1>&2
|
73 |
|
|
exit 1
|