source: hooks/pre-commit.tmpl@ 429

Last change on this file since 429 was 202, checked in by luciano, 11 years ago
File size: 3.4 KB
Line 
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# The default working directory for the invocation is undefined, so
25# the program should set one explicitly if it cares.
26#
27# If the hook program exits with success, the txn is committed; but
28# if it exits with failure (non-zero), the txn is aborted, no commit
29# takes place, and STDERR is returned to the client. The hook
30# program can use the 'svnlook' utility to help it examine the txn.
31#
32# On a Unix system, the normal procedure is to have 'pre-commit'
33# invoke other programs to do the real work, though it may do the
34# work itself too.
35#
36# *** NOTE: THE HOOK PROGRAM MUST NOT MODIFY THE TXN, EXCEPT ***
37# *** FOR REVISION PROPERTIES (like svn:log or svn:author). ***
38#
39# This is why we recommend using the read-only 'svnlook' utility.
40# In the future, Subversion may enforce the rule that pre-commit
41# hooks should not modify the versioned data in txns, or else come
42# up with a mechanism to make it safe to do so (by informing the
43# committing client of the changes). However, right now neither
44# mechanism is implemented, so hook writers just have to be careful.
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 typically does not inherit the environment of
55# its parent process. For example, a common problem is for the
56# 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# Here is an example hook script, for a Unix /bin/sh interpreter.
62# For more examples and pre-written hooks, see those in
63# /usr/share/subversion/hook-scripts, and in the repository at
64# http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/ and
65# http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/
66
67
68REPOS="$1"
69TXN="$2"
70
71# Make sure that the log message contains some text.
72SVNLOOK=/usr/bin/svnlook
73$SVNLOOK log -t "$TXN" "$REPOS" | \
74 grep "[a-zA-Z0-9]" > /dev/null || exit 1
75
76# Exit on all errors.
77set -e
78
79# Check that the author of this commit has the rights to perform
80# the commit on the files and directories being modified.
81"$REPOS"/hooks/commit-access-control.pl "$REPOS" $TXN \
82 "$REPOS"/hooks/commit-access-control.cfg
83
84# All checks passed, so allow the commit.
85exit 0
Note: See TracBrowser for help on using the repository browser.