Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2227 - 1
#!/bin/sh
2
 
3
# PRE-COMMIT HOOK
4
#
5
# The pre-commit hook is invoked before a Subversion txn is
6
# committed.  Subversion runs this hook by invoking a program
7
# (script, executable, binary, etc.) named 'pre-commit' (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] TXN-NAME     (the name of the txn about to be committed)
12
#
13
#   [STDIN] LOCK-TOKENS ** the lock tokens are passed via STDIN.
14
#
15
#   If STDIN contains the line "LOCK-TOKENS:\n" (the "\n" denotes a
16
#   single newline), the lines following it are the lock tokens for
17
#   this commit.  The end of the list is marked by a line containing
18
#   only a newline character.
19
#
20
#   Each lock token line consists of a URI-escaped path, followed
21
#   by the separator character '|', followed by the lock token string,
22
#   followed by a newline.
23
#
24
# If the hook program exits with success, the txn is committed; but
25
# if it exits with failure (non-zero), the txn is aborted, no commit
26
# takes place, and STDERR is returned to the client.   The hook
27
# program can use the 'svnlook' utility to help it examine the txn.
28
#
29
#   ***  NOTE: THE HOOK PROGRAM MUST NOT MODIFY THE TXN, EXCEPT  ***
30
#   ***  FOR REVISION PROPERTIES (like svn:log or svn:author).   ***
31
#
32
#   This is why we recommend using the read-only 'svnlook' utility.
33
#   In the future, Subversion may enforce the rule that pre-commit
34
#   hooks should not modify the versioned data in txns, or else come
35
#   up with a mechanism to make it safe to do so (by informing the
36
#   committing client of the changes).  However, right now neither
37
#   mechanism is implemented, so hook writers just have to be careful.
38
#
39
# The default working directory for the invocation is undefined, so
40
# the program should set one explicitly if it cares.
41
#
42
# On a Unix system, the normal procedure is to have 'pre-commit'
43
# invoke other programs to do the real work, though it may do the
44
# work itself too.
45
#
46
# Note that 'pre-commit' must be executable by the user(s) who will
47
# invoke it (typically the user httpd runs as), and that user must
48
# have filesystem-level permission to access the repository.
49
#
50
# On a Windows system, you should name the hook program
51
# 'pre-commit.bat' or 'pre-commit.exe',
52
# but the basic idea is the same.
53
#
54
# The hook program runs in an empty environment, unless the server is
55
# explicitly configured otherwise.  For example, a common problem is for
56
# the PATH environment variable to not be set to its usual value, so
57
# that subprograms fail to launch unless invoked via absolute path.
58
# If you're having unexpected problems with a hook program, the
59
# culprit may be unusual (or missing) environment variables.
60
#
61
# CAUTION:
62
# For security reasons, you MUST always properly quote arguments when
63
# you use them, as those arguments could contain whitespace or other
64
# problematic characters. Additionally, you should delimit the list
65
# of options with "--" before passing the arguments, so malicious
66
# clients cannot bootleg unexpected options to the commands your
67
# script aims to execute.
68
# For similar reasons, you should also add a trailing @ to URLs which
69
# are passed to SVN commands accepting URLs with peg revisions.
70
#
71
# Here is an example hook script, for a Unix /bin/sh interpreter.
72
# For more examples and pre-written hooks, see those in
73
# the Subversion repository at
74
# http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/ and
75
# http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/
76
 
77
 
78
REPOS="$1"
79
TXN="$2"
80
 
81
# Make sure that the log message contains some text.
82
SVNLOOK=/usr/local/bin/svnlook
83
$SVNLOOK log -t "$TXN" "$REPOS" | \
84
   grep "[a-zA-Z0-9]" > /dev/null || exit 1
85
 
86
# Check that the author of this commit has the rights to perform
87
# the commit on the files and directories being modified.
88
commit-access-control.pl "$REPOS" "$TXN" commit-access-control.cfg || exit 1
89
 
90
# All checks passed, so allow the commit.
91
exit 0