very basic and raw CouchDb Commandline Client
[couchdbimport.git] / hooks / pre-lock.tmpl
blobf4c43d25d56bd4aea630abf40ee347e6347e1832
1 #!/bin/sh
3 # PRE-LOCK HOOK
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:
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)
14 # The default working directory for the invocation is undefined, so
15 # the program should set one explicitly if it cares.
17 # If the hook program exits with success, the lock is created; but
18 # if it exits with failure (non-zero), the lock action is aborted
19 # and STDERR is returned to the client.
21 # On a Unix system, the normal procedure is to have 'pre-lock'
22 # invoke other programs to do the real work, though it may do the
23 # work itself too.
25 # Note that 'pre-lock' 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.
29 # On a Windows system, you should name the hook program
30 # 'pre-lock.bat' or 'pre-lock.exe',
31 # but the basic idea is the same.
33 # Here is an example hook script, for a Unix /bin/sh interpreter:
35 REPOS="$1"
36 PATH="$2"
37 USER="$3"
39 # If a lock exists and is owned by a different person, don't allow it
40 # to be stolen (e.g., with 'svn lock --force ...').
42 # (Maybe this script could send email to the lock owner?)
43 SVNLOOK=/usr/local/bin/svnlook
44 GREP=/bin/grep
45 SED=/bin/sed
47 LOCK_OWNER=`$SVNLOOK lock "$REPOS" "$PATH" | \
48 $GREP '^Owner: ' | $SED 's/Owner: //'`
50 # If we get no result from svnlook, there's no lock, allow the lock to
51 # happen:
52 if [ "$LOCK_OWNER" = "" ]; then
53 exit 0
56 # If the person locking matches the lock's owner, allow the lock to
57 # happen:
58 if [ "$LOCK_OWNER" = "$USER" ]; then
59 exit 0
62 # Otherwise, we've got an owner mismatch, so return failure:
63 echo "Error: $PATH already locked by ${LOCK_OWNER}." 1>&2
64 exit 1