2a4a039fdf1c2e4a703f8c4656608dc2fc7ba5df
[hooke.git] / hooks / pre-lock.tmpl
1 #!/bin/sh\r
2 \r
3 # PRE-LOCK HOOK\r
4 #\r
5 # The pre-lock hook is invoked before an exclusive lock is\r
6 # created.  Subversion runs this hook by invoking a program \r
7 # (script, executable, binary, etc.) named 'pre-lock' (for which\r
8 # this file is a template), with the following ordered arguments:\r
9 #\r
10 #   [1] REPOS-PATH   (the path to this repository)\r
11 #   [2] PATH         (the path in the repository about to be locked)\r
12 #   [3] USER         (the user creating the lock)\r
13 #   [4] COMMENT      (the comment of the lock)\r
14 #   [5] STEAL-LOCK   (1 if the user is trying to steal the lock, else 0)\r
15 #\r
16 # If the hook program outputs anything on stdout, the output string will\r
17 # be used as the lock token for this lock operation.  If you choose to use\r
18 # this feature, you must guarantee the tokens generated are unique across\r
19 # the repository each time.\r
20 #\r
21 # The default working directory for the invocation is undefined, so\r
22 # the program should set one explicitly if it cares.\r
23 #\r
24 # If the hook program exits with success, the lock is created; but\r
25 # if it exits with failure (non-zero), the lock action is aborted\r
26 # and STDERR is returned to the client.\r
27 \r
28 # On a Unix system, the normal procedure is to have 'pre-lock'\r
29 # invoke other programs to do the real work, though it may do the\r
30 # work itself too.\r
31 #\r
32 # Note that 'pre-lock' must be executable by the user(s) who will\r
33 # invoke it (typically the user httpd runs as), and that user must\r
34 # have filesystem-level permission to access the repository.\r
35 #\r
36 # On a Windows system, you should name the hook program\r
37 # 'pre-lock.bat' or 'pre-lock.exe',\r
38 # but the basic idea is the same.\r
39 #\r
40 # Here is an example hook script, for a Unix /bin/sh interpreter:\r
41 \r
42 REPOS="$1"\r
43 PATH="$2"\r
44 USER="$3"\r
45 \r
46 # If a lock exists and is owned by a different person, don't allow it\r
47 # to be stolen (e.g., with 'svn lock --force ...').\r
48 \r
49 # (Maybe this script could send email to the lock owner?)\r
50 SVNLOOK=/usr/local/bin/svnlook\r
51 GREP=/bin/grep\r
52 SED=/bin/sed\r
53 \r
54 LOCK_OWNER=`$SVNLOOK lock "$REPOS" "$PATH" | \\r
55             $GREP '^Owner: ' | $SED 's/Owner: //'`\r
56 \r
57 # If we get no result from svnlook, there's no lock, allow the lock to\r
58 # happen:\r
59 if [ "$LOCK_OWNER" = "" ]; then\r
60   exit 0\r
61 fi\r
62 \r
63 # If the person locking matches the lock's owner, allow the lock to\r
64 # happen:\r
65 if [ "$LOCK_OWNER" = "$USER" ]; then\r
66   exit 0\r
67 fi\r
68 \r
69 # Otherwise, we've got an owner mismatch, so return failure:\r
70 echo "Error: $PATH already locked by ${LOCK_OWNER}." 1>&2\r
71 exit 1\r