Validating commit log messages in VisualSVN Server

Applies to: VisualSVN Server 3.9 and later

VisualSVN Server includes a pre-commit hook that allows putting certain restrictions on the log messages for the new commits. Typically, you might want to prohibit empty or short log messages, or log messages without certain text (e.g., without an issue number or ID).

Follow these steps to enable the pre-commit hook:

  1. Start the VisualSVN Server Manager console.
  2. Expand the Repositories node.
  3. Right-click the repository and click Properties.
  4. Click the Hooks tab.
  5. Double-click the Pre-commit hook.
  6. Enter the following commands replacing the parameters with valid values.
    "%VISUALSVN_SERVER%\bin\VisualSVNServerHooks.exe" ^
    check-logmessage "%1" -t "%2" ^
    --min-size <min-size>
    IF ERRORLEVEL 1 exit /b 1
    
    Tip
    You can find the script examples below.
  7. Click OK and Apply.
Note
Do not forget to use IF ERRORLEVEL 1 exit /b 1 or a similar condition after calling VisualSVNServerHooks.exe in the hook script. Otherwise, the results of the check will be silently ignored.

The check-logmessage command accepts the following options:

Option Meaning
-t [--transaction] ARG Specifies the transaction ID
--min-size ARG Minimum allowed number of characters in the commit log message
--regexp ARG Regular expression to validate a message.

The option is available starting with VisualSVN Server 5.2.
--filter ARG Include changes only in specified paths.

The option is available starting with VisualSVN Server 5.2.

Examples

Below you can find examples of scripts that you can use in your repositories.

Reject commits with less than 10 characters in the log message

Use the following pre-commit hook to reject commits with less than 10 characters in the log message:

"%VISUALSVN_SERVER%\bin\VisualSVNServerHooks.exe" ^
check-logmessage "%1" -t "%2" ^
--min-size 10
IF ERRORLEVEL 1 exit /b 1

Reject commits without an issue ID in the log message

Use the following pre-commit hook to require an issue number in the commit log message. The hook validates the log message against the regular expression ISSUE-\d+ and rejects the commit with a custom error message when the issue number is missing.

"%VISUALSVN_SERVER%\bin\VisualSVNServerHooks.exe" check-logmessage ^
  --regexp "ISSUE-\d+" ^
  -t "%2" "%1"
IF ERRORLEVEL 1 echo Issue number must be specified. >&2 & exit /b 1

Reject commits into '/project' without an issue ID in the log message

Use the following pre-commit hook to require an issue number in log messages of commits into the /project subtree of the repository. The hook validates the log message against the regular expression ISSUE-\d+, but only for commits into /project in the repository.

"%VISUALSVN_SERVER%\bin\VisualSVNServerHooks.exe" check-logmessage ^
  --regexp "ISSUE-\d+" ^
  --filter /project ^
  -t "%2" "%1"
IF ERRORLEVEL 1 exit /b 1

See also

SVNBook | pre-commit hook

Last Modified: