Project

Profile

Help

How to connect?
Download (2.14 KB) Statistics
| Branch: | Tag: | Revision:

he / hooks / pre-unlock.tmpl @ c74fd4aa

1
#!/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
#   [4] TOKEN        (the lock token to be destroyed)
14
#   [5] BREAK-UNLOCK (1 if the user is breaking the lock, else 0)
15
#
16
# The default working directory for the invocation is undefined, so
17
# the program should set one explicitly if it cares.
18
#
19
# If the hook program exits with success, the lock is destroyed; but
20
# if it exits with failure (non-zero), the unlock action is aborted
21
# and STDERR is returned to the client.
22

    
23
# On a Unix system, the normal procedure is to have 'pre-unlock'
24
# invoke other programs to do the real work, though it may do the
25
# work itself too.
26
#
27
# Note that 'pre-unlock' must be executable by the user(s) who will
28
# invoke it (typically the user httpd runs as), and that user must
29
# have filesystem-level permission to access the repository.
30
#
31
# On a Windows system, you should name the hook program
32
# 'pre-unlock.bat' or 'pre-unlock.exe',
33
# but the basic idea is the same.
34
#
35
# Here is an example hook script, for a Unix /bin/sh interpreter:
36

    
37
REPOS="$1"
38
PATH="$2"
39
USER="$3"
40
TOKEN="$4"
41
BREAK="$5"
42

    
43
# If a lock is owned by a different person, don't allow it be broken.
44
# (Maybe this script could send email to the lock owner?)
45

    
46
SVNLOOK=/usr/local/bin/svnlook
47
GREP=/bin/grep
48
SED=/bin/sed
49

    
50
LOCK_OWNER=`$SVNLOOK lock "$REPOS" "$PATH" | \
51
            $GREP '^Owner: ' | $SED 's/Owner: //'`
52

    
53
# If we get no result from svnlook, there's no lock, return success:
54
if [ "$LOCK_OWNER" = "" ]; then
55
  exit 0
56
fi
57

    
58
# If the person unlocking matches the lock's owner, return success:
59
if [ "$LOCK_OWNER" = "$USER" ]; then
60
  exit 0
61
fi
62

    
63
# Otherwise, we've got an owner mismatch, so return failure:
64
echo "Error: $PATH locked by ${LOCK_OWNER}." 1>&2
65
exit 1
(8-8/9)