1 |
21
|
pcwacht
|
#!/bin/sh
|
2 |
|
|
|
3 |
|
|
# PRE-UNLOCK HOOK
|
4 |
|
|
#
|
5 |
|
|
# The pre-unlock hook is invoked before an exclusive lock is
|
6 |
|
|
# destroyed. Subversion runs this hook by invoking a program
|
7 |
|
|
# (script, executable, binary, etc.) named 'pre-unlock' (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 unlocked)
|
12 |
|
|
# [3] USER (the user destroying the lock)
|
13 |
|
|
#
|
14 |
|
|
# The default working directory for the invocation is undefined, so
|
15 |
|
|
# the program should set one explicitly if it cares.
|
16 |
|
|
#
|
17 |
|
|
# If the hook program exits with success, the lock is destroyed; but
|
18 |
|
|
# if it exits with failure (non-zero), the unlock action is aborted
|
19 |
|
|
# and STDERR is returned to the client.
|
20 |
|
|
|
21 |
|
|
# On a Unix system, the normal procedure is to have 'pre-unlock'
|
22 |
|
|
# invoke other programs to do the real work, though it may do the
|
23 |
|
|
# work itself too.
|
24 |
|
|
#
|
25 |
|
|
# Note that 'pre-unlock' must be executable by the user(s) who will
|
26 |
|
|
# invoke it (typically the user httpd runs as), and that user must
|
27 |
|
|
# have filesystem-level permission to access the repository.
|
28 |
|
|
#
|
29 |
|
|
# On a Windows system, you should name the hook program
|
30 |
|
|
# 'pre-unlock.bat' or 'pre-unlock.exe',
|
31 |
|
|
# but the basic idea is the same.
|
32 |
|
|
#
|
33 |
|
|
# Here is an example hook script, for a Unix /bin/sh interpreter:
|
34 |
|
|
|
35 |
|
|
REPOS="$1"
|
36 |
|
|
PATH="$2"
|
37 |
|
|
USER="$3"
|
38 |
|
|
|
39 |
|
|
# If a lock is owned by a different person, don't allow it be broken.
|
40 |
|
|
# (Maybe this script could send email to the to the lock owner?)
|
41 |
|
|
|
42 |
|
|
SVNLOOK=/usr/local/bin/svnlook
|
43 |
|
|
GREP=/bin/grep
|
44 |
|
|
SED=/bin/sed
|
45 |
|
|
|
46 |
|
|
LOCK_OWNER=`$SVNLOOK lock "$REPOS" "$PATH" | \
|
47 |
|
|
$GREP '^Owner: ' | $SED 's/Owner: //'`
|
48 |
|
|
|
49 |
|
|
# If we get no result from svnlook, there's no lock, return success:
|
50 |
|
|
if [ "$LOCK_OWNER" == "" ]; then
|
51 |
|
|
exit 0
|
52 |
|
|
fi
|
53 |
|
|
# If the person unlocking matches the lock's owner, return success:
|
54 |
|
|
if [ "$LOCK_OWNER" == "$USER" ]; then
|
55 |
|
|
exit 0
|
56 |
|
|
fi
|
57 |
|
|
|
58 |
|
|
# Otherwise, we've got an owner mismatch, so return failure:
|
59 |
|
|
echo "Error: $PATH locked by ${LOCK_OWNER}." 1>&2
|
60 |
|
|
exit 1
|