Edgewall Software

Ticket #897: pre-commit.cmd

File pre-commit.cmd, 2.5 KB (added by anonymous, 7 years ago)

pre-commit hook (no need to change anything in trac)

Line 
1@ECHO OFF
2REM PRE-COMMIT HOOK
3REM
4REM The pre-commit hook is invoked before a Subversion txn is
5REM committed.  Subversion runs this hook by invoking a program
6REM (script, executable, binary, etc.) named 'pre-commit' (for which
7REM this file is a template), with the following ordered arguments:
8REM
9REM   [1] REPOS-PATH   (the path to this repository)
10REM   [2] TXN-NAME     (the name of the txn about to be committed)
11REM
12REM The default working directory for the invocation is undefined, so
13REM the program should set one explicitly if it cares.
14REM
15REM If the hook program exits with success, the txn is committed; but
16REM if it exits with failure (non-zero), the txn is aborted, no commit
17REM takes place, and STDERR is returned to the client.   The hook
18REM program can use the 'svnlook' utility to help it examine the txn.
19REM
20REM On a Unix system, the normal procedure is to have 'pre-commit'
21REM invoke other programs to do the real work, though it may do the
22REM work itself too.
23REM
24REM   ***  NOTE: THE HOOK PROGRAM MUST NOT MODIFY THE TXN, EXCEPT  ***
25REM   ***  FOR REVISION PROPERTIES (like svn:log or svn:author).   ***
26REM
27REM   This is why we recommend using the read-only 'svnlook' utility.
28REM   In the future, Subversion may enforce the rule that pre-commit
29REM   hooks should not modify the versioned data in txns, or else come
30REM   up with a mechanism to make it safe to do so (by informing the
31REM   committing client of the changes).  However, right now neither
32REM   mechanism is implemented, so hook writers just have to be careful.
33REM
34REM Note that 'pre-commit' must be executable by the user(s) who will
35REM invoke it (typically the user httpd runs as), and that user must
36REM have filesystem-level permission to access the repository.
37REM
38REM On a Windows system, you should name the hook program
39REM 'pre-commit.bat' or 'pre-commit.exe',
40REM but the basic idea is the same.
41REM
42REM Here is an example hook script, for a Windows CMD.exe interpreter:
43
44SET REPOS=%1
45SET TXN=%2
46
47SET SVN_DIR=C:\Program Files\Subversion
48SET PYTHON_DIR=C:\Program Files\Python23
49SET HOOKS_DIR=C:\... the hook folder of the repository ...\hooks
50SET TRAC_ENV=C:\... trac folder ...\trac.db
51
52SET PYTHON="%PYTHON_DIR%\python.exe"
53SET SVN="%SVN_DIR%\bin\svn.exe"
54SET SVNADMIN="%SVN_DIR%\bin\svnadmin.exe"
55SET SVNLOOK="%SVN_DIR%\bin\svnlook.exe"
56
57FOR /F "usebackq delims==" %%i IN (`%%SVNLOOK%% log -t %TXN% %REPOS%`)
58DO SET LOG=%%i
59
60%PYTHON% "%HOOKS_DIR%\trac-pre-commit-hook" "%TRAC_ENV%" "%LOG%" || exit 1