How to export revision on commit with a post-commit hook?

混江龙づ霸主 提交于 2019-12-08 06:30:19

问题


It may be handy to export the specific Subversion repository branch after a commit, using a post-commit hook.

E.g. to update a website after a commit or to update a development branch for testing.

Is there any instruction or sample of such a hook?


回答1:


The best choice for writing a hook script for Subversion in Windows environment (e.g. VisualSVN Server) is to use Windows PowerShell scripting language or good ol' Windows batch command-line.

Here is the sample code of post-commit.bat and post-commit.ps1 that should be used together to export a committed revision to C:\Test. Put them into your repository 'hooks' folder, e.g. C:\Repositories\repository\hooks\

post-commit.ps1

# Store hook arguments into variables with mnemonic names
$repos = $args[0]
$rev   = $args[1]

# Build path to svn.exe
$svn = "$env:VISUALSVN_SERVER\bin\svn.exe"

# Build url to repository
$urepos = $repos -replace "\\", "/"
$url = "file:///$urepos/"

# Export repository revision $rev to the C:\test folder
&"$svn" export -r $rev --force "$url" c:\test

post-commit.bat

@echo off

set PWSH=%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
%PWSH% -command $input ^| %1\hooks\post-commit.ps1 %1 %2  
if errorlevel 1 exit %errorlevel%


来源:https://stackoverflow.com/questions/11540298/how-to-export-revision-on-commit-with-a-post-commit-hook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!