Search code examples
pythonwindowssvnvisualsvn-serverpre-commit-hook

How to call a python script in visualsvn server precommit hook running on windows


I Implement a python script for the pre-commit hook to detect the commit message, author, changed path then throw exception or error in specifics cases.

I want to set this script pre-commit.py in the VisualSVN server Pre-commit Hook using this command in the Hooks

C:\Users\momo\Desktop\pre-commit.py %1 %2

When I want to commit I got this error Access Denied looks like pre-commit hook doesn't recognize my syntax


enter image description here


Solution

  • Python scripts are not considered as executable files on Windows. You should wrap them around in Windows Batch. For example, a pre-commit hook script can look as follows:

    set REPOS-PATH=%1
    set TXN-NAME=%2
    "C:\Python27\python.exe" "C:\Repositories\MyRepository\hooks\pre-commit.py" %REPOS-PATH% %TXN-NAME%
    

    This Windows Batch script will run Python script located at C:\Repositories\MyRepository\hooks\post-commit.py and will pass the %1 and %2 arguments.

    Put this code into your repository's \hooks\pre-commit.bat or \hooks\pre-commit.cmd file manually or via the VisualSVN Server Manager console:

    1. Start the VisualSVN Server Manager console.
    2. Right-click a repository and click Properties.
    3. Click the Hooks tab.
    4. Click the Pre-commit hook and click Edit.