如何使用提交后钩子导出提交时的修订版本? [英] How to export revision on commit with a post-commit hook?

查看:92
本文介绍了如何使用提交后钩子导出提交时的修订版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用提交后挂钩在提交后导出特定的Subversion存储库分支可能很方便.

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?

推荐答案

在Windows环境中为Subversion编写钩子脚本的最佳选择(例如 VisualSVN服务器)将使用 Windows PowerShell 脚本编写语言还是其他语言 Windows批处理命令行.

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.

以下是 post-commit.bat post-commit.ps1 的示例代码,应将它们一起用于将提交的修订版本导出到C:\Test.将它们放入您的存储库挂钩"文件夹,例如C:\Repositories\repository\hooks\

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

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

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%

这篇关于如何使用提交后钩子导出提交时的修订版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆