11.07.2015 Views

Version Control with Subversion - Login

Version Control with Subversion - Login

Version Control with Subversion - Login

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Repository AdministrationImplementing Repository HooksA hook is a program triggered by some repository event, such as the creation of a new revisionor the modification of an unversioned property. Some hooks (the so-called “prehooks”) run in advance of a repository operation and provide a means by which to both reportwhat is about to happen and prevent it from happening at all. Other hooks (the “posthooks”) run after the completion of a repository event and are useful for performing tasksthat examine—but don't modify—the repository. Each hook is handed enough informationto tell what that event is (or was), the specific repository changes proposed (or completed),and the username of the person who triggered the event.The hooks subdirectory is, by default, filled <strong>with</strong> templates for various repository hooks:$ ls repos/hooks/post-commit.tmpl post-unlock.tmpl pre-revprop-change.tmplpost-lock.tmpl pre-commit.tmpl pre-unlock.tmplpost-revprop-change.tmpl pre-lock.tmpl start-commit.tmpl$There is one template for each hook that the <strong>Subversion</strong> repository supports; by examiningthe contents of those template scripts, you can see what triggers each script to run andwhat data is passed to that script. Also present in many of these templates are examples ofhow one might use that script, in conjunction <strong>with</strong> other <strong>Subversion</strong>-supplied programs, toperform common useful tasks. To actually install a working hook, you need only placesome executable program or script into the repos/hooks directory, which can be executedas the name (such as start-commit or post-commit) of the hook.On Unix platforms, this means supplying a script or program (which could be a shell script,a Python program, a compiled C binary, or any number of other things) named exactly likethe name of the hook. Of course, the template files are present for more than just informationalpurposes—the easiest way to install a hook on Unix platforms is to simply copy theappropriate template file to a new file that lacks the .tmpl extension, customize the hook'scontents, and ensure that the script is executable. Windows, however, uses file extensionsto determine whether a program is executable, so you would need to supply a programwhose basename is the name of the hook and whose extension is one of the special extensionsrecognized by Windows for executable programs, such as .exe for programs and.bat for batch files.For security reasons, the <strong>Subversion</strong> repository executes hook programs <strong>with</strong>an empty environment—that is, no environment variables are set at all, noteven $PATH (or %PATH%, under Windows). Because of this, many administratorsare baffled when their hook program runs fine by hand, but doesn't workwhen run by <strong>Subversion</strong>. Be sure to explicitly set any necessary environmentvariables in your hook program and/or use absolute paths to programs.<strong>Subversion</strong> executes hooks as the same user who owns the process that is accessing the<strong>Subversion</strong> repository. In most cases, the repository is being accessed via a <strong>Subversion</strong>server, so this user is the same user as whom the server runs on the system. The hooksthemselves will need to be configured <strong>with</strong> OS-level permissions that allow that user to executethem. Also, this means that any programs or files (including the <strong>Subversion</strong> repository)accessed directly or indirectly by the hook will be accessed as the same user. In otherwords, be alert to potential permission-related problems that could prevent the hook fromperforming the tasks it is designed to perform.There are serveral hooks implemented by the <strong>Subversion</strong> repository, and you can get detailsabout each of them in the section called “Repository Hooks”. As a repository administrator,you'll need to decide which hooks you wish to implement (by way of providing an appropriatelynamed and permissioned hook program), and how. When you make this decision,keep in mind the big picture of how your repository is deployed. For example, if you130

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!