Svn – VisualSVN Server doesn’t trigger post-commit hook

svnvisualsvn-server

I have an issue that is driving me crazy.
I want to integrate VisualSVN Server with Mantis BT, so when I commit from the svn client, and I comment something like "fixed issue #3" then the issue in Mantis is marked as resolved.

I followed the steps in http://arklad.wordpress.com/2010/01/07/communicating-mantis-and-subversion-on-windows/

So I create an user in Mantis named 'svn' with developer role, and assigned to my project.
I've edited my mantis config.inc and it looks like this:

<?php
$g_hostname = 'databaseserver';
$g_db_type = 'mssqlnative';
$g_database_name = 'mantisbt';
$g_db_username = 'mantis';
$g_db_password = 'mypass';

$g_allow_file_upload = ON;
$g_file_upload_method = DISK;

# User account that connects with Subversion
$g_source_control_account = 'svn';

    # Regular expression to be matched in the comments
    # Example: issue #1
    $g_source_control_regexp = '/\b(?:bug|issue|error)\s*[#]{0,1}(\d+)\b/i';

    # Regular expression to be matched to fix an issue
    # Example: fixed issue #1
    $g_source_control_fixed_regexp = '/\b(?:fixed|fixes|resolved)\s+(?:bug|issue|error)?\s*[#](\d+)\b/i';
    # Status after solving the issue
    $g_source_control_set_status_to = RESOLVED;
    # Resolution after solving the issue
    $g_source_control_set_resolution_to = FIXED;
?>

Then I create the post-commit.bat file and place it in the hooks folder:

@ECHO on
SET REPOS=%1
SET REV=%2

SET PHP="C:\Program Files (x86)\PHP\v5.3\php.exe"
SET CHECKIN="C:\WebSites\mantisbt-1.2.14\scripts\checkin.php"
SET SVNLOOK="C:\Program Files (x86)\VisualSVN Server\bin\svnlook.exe"

SET LOGFILE=C:\log.txt
SET AUTHORFILE=C:\author.txt
SET OUTPUTFILE=C:\output.txt

%SVNLOOK% log -r %REV% %REPOS% > %LOGFILE%
%SVNLOOK% author -r %REV% %REPOS% > %AUTHORFILE%

TYPE %LOGFILE% > %OUTPUTFILE%

%PHP% %CHECKIN% < %OUTPUTFILE% >> %LOGFILE%
ECHO "Post-commit for revision %REV% finished" >> %LOGFILE%
@ECHO off

All the paths are allright (checked many times) and the .bat executes well when I run separately (It creates the output files).

I came to the conclusion that VisualSVN is not triggering the post-commit.bat. I restarted many times the server also. What am I doing wrong?

Best Answer

Double-check whether VisualSVN Server service account (Network Service account by default) has access permissions to all files and folders the post-commit script attempts to touch or operate with.

I think that 'no access' to these locations is the root cause:

  • C:\Program Files (x86)\PHP\v5.3\ and it's childs,
  • C:\WebSites\mantisbt-1.2.14\scripts\ and it's childs.

There can be various reasons for a hook script not to work. You should troubleshoot the hook and get the error output to understand the cause. Error output helps to understand the root cause and fix it.

In order to capture output to a log file you can do the following:

  1. Rename your current post-commit.bat file to post-commit-run.bat,

  2. Create the following file as your post-commit.bat file:

    call "%~dp0post-commit-run.bat" %* > %1/hooks/post-commit.log 2>&1

  3. Commit to the repository and check the generated log file.

Related Topic