|
Subversion Hook: Review Before Commit |
Top Previous Next |
|
The Review-Before-Commit rule enforces that code must be reviewed in Code Collaborator before it can be committed to the Subversion server. To enforce this rule, you must first require developers to put the review ID somewhere in the Subversion commit message. The format of this text is completely up to you; you will later need to supply a Java-style regular expression that identifies this text and specifically calls out the review ID inside that text. Here are some common ways of specifying the review ID and the corresponding regular expressions. Note that regular expressions are case-insensitive and you must identify the review ID portion with parenthesis:
This text can appear in-line with other text or in a more formal "form-style" layout. Because you control the regular expression, you can control exactly what this looks like. Prerequisites You must have both svnlook and svn installed on your Subversion server, as well as the Code Collaborator Command Line Client. The Code Collaborator server does not have to be on the same server, but the Command Line Client must have been configured to communicate with the server. Setting up the Subversion server-side hook To implement the trigger you will need to add a line to your pre-commit Subversion trigger. This is located inside the /hooks subdirectory in your Subversion repository, and you should refer to the Subversion documentation for details. If you already have a pre-commit hook, you can add our tool wherever it is appropriate; otherwise you will need to create an executable hook as described in the Subversion documentation (typically a batch file under Windows or a shell script under Linux/Mac). The exact form of the command depends on your environment. Here are the parts with examples of what each part might look like:
An example of what our trigger command might look like in a Linux/OS X shell script (but all on one line): /collab/install/subversiontrigger ensurereviewed $1 $2 "/usr/bin/svnlook" "svn://myserver/myrepo" "review:\\s+(\\d+)" || exit 1
Another example of what our trigger command might look like in a Windows batch file (but all on one line): "C:\Program Files\Code Collaborator Client\subversiontrigger.exe" ensurereviewed %1 %2 "C:\Program Files\Subversion\bin\svnlook.exe" "svn://myserver/myrepo" "review:\\s+(\\d+)" || exit 1
Note our use of "exit 1" to ensure that the script terminates with a non-zero exit code if our trigger application fails. This is vital -- if you don't do this the trigger will not prevent the commit. Usage notes Our trigger application provides good error messages, so when you're setting it up it will tell you exactly what's wrong, and when your configuration is right and users run into normal errors (e.g. review ID not specified, review doesn't exist, review isn't complete, review doesn't contain one of the files you're trying to check in), that user will get an appropriate and specific error message. This trigger works with all Subversion clients because it runs on the server. If you want to restrict the trigger to certain users or files, you will need to do this yourself in the pre-commit script. You can examine the transaction and run our application only if applicable. |