Trac has the capability to synchronize with Subversion whenever a commit is performed on a repository. Unfortunately, the documentation leads down many paths and it is not clear which file is supposed to go where so this tutorial should summarize a working configuration.
The following diagram is a filesystem representation starting from the root / and showing the path to a project named project with the svn repository located at /srv/svn/project and the path to the trac environment located at /srv/trac/env/project.
/
+
|
+--+ srv
+
|
+--+ svn
| +
| |
| +--+ project
| +
| |
| +--+ conf
| | +
| | |
| | +--+ hooks-env
| |
| +--+ hooks
| +
| |
| +--+ post-commit
|
|
+--+ trac
+
|
+--+ env
| +
| |
| +--+ project
|
+--+ .trac-svn-hook
The relevant files in this setup are; for the Subversion project:
/srv/svn/project/conf/hooks-env/srv/svn/project/hooks/post-commitand for trac:
/srv/trac/.trac-svn-hook
The Trac Subversion scripts is provided in the contrib directory of the Trac project or can be downloaded online and placed as a hidden file at /srv/trac/.trac-svn-hook (one directory up from the Trac environment directory).
The script needs a few changes in the Configuration section of the file. Instead of the defaults:
# export TRAC_ENV=/path/to/trac-env:/path/to/another/trac-env # export PATH=/path/to/python/bin:$PATH # export LD_LIBRARY_PATH=/path/to/python/lib:$LD_LIBRARY_PATH
replace with:
export PATH=$PYTHON_BIN:$PATH export LD_LIBRARY_PATH=$PYTHON_LIB:$LD_LIBRARY_PATH
The TRAC_ENV variable does not have to be set and can be set in the Subversion post-commit hook.
There are two files to be modified inside the Subversion repository:
/srv/svn/project/conf/hooks-env/srv/svn/project/hooks/post-commit
The file at /srv/svn/project/conf/hooks-env should be altered to contain the following:
[default] LANG = en_US.UTF-8 ### Set this to the path to the trac environment for the project. TRAC_ENV=/srv/trac/env/project PYTHON_BIN=/usr/bin:$PATH PYTHON_LIB=$LD_LIBRARY_PATH ### This sets the PATH environment variable for the pre-commit hook. [pre-commit] PATH = /usr/local/bin:/usr/bin:/usr/sbin
where:
TRAC_ENV must be changed to point to the trac environment for the project (in this case, the trac environment for the project named project is located at /srv/trac/env/project).Also in the Subversion project directory, the post-commit script located at:
/srv/svn/project/hooks/post-commitmust be changed to contain the following:
#!/bin/sh REPOS="$1" REV="$2" /srv/trac/.trac-svn-hook $REPOS $REV
where /srv/trac/.trac-svn-hook is the full path to the .trac-svn-hook file from the Trac contrib directory.
To check that the setup works, a file can be committed to the repository and then deleted and the changes should show up shortly in the Trac source code view. In case something goes wrong, the client committing the file should retrieve an error about the post-commit script not terminating gracefully.
For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.