帮助subversion(svn)钩子脚本

时间:2009-12-18 00:04:31

标签: svn scripting tortoisesvn svn-hooks

如何创建一个subversion服务器钩子脚本,如果他们没有首先拥有对文件的锁定,就会阻止人们提交更改?

Svn服务器在Windows上。

感谢。

P.S。此问题中的其他信息

Subversion (svn + tortoiseSvn) commit not locked file

2 个答案:

答案 0 :(得分:4)

使用预提交挂钩。预提交钩子接收2个参数:

#   [1] REPOS-PATH   (the path to this repository)
#   [2] TXN-NAME     (the name of the txn about to be committed)

您需要使用svnlook来确定是否存在未锁定的svn:needs-lock文件。

确定此提交更改的路径:

svnlook changed $1 --transaction $2

在'changed'中循环浏览文件($PATH as loop item)并确定svn:needs-lock,如果它们当前已被锁定:

svnlook propget $REPOS-PATH svn:needs-lock $PATH
svnlook lock $1 $PATH

写入stderr并返回非零以在需要时中止此提交。

答案 1 :(得分:1)

你可以使用<your repos directory>/hooks/pre-commit并使用一些批处理脚本(甚至是一个完整的程序,只要它是可执行的就可以了)。如果返回 0 ,则提交将成功;否则就会失败。

有关示例,请参阅同一目录中的post-lock.tmpl

# PRE-COMMIT HOOK
#
# The pre-commit hook is invoked before a Subversion txn is
# committed.  Subversion runs this hook by invoking a program
# (script, executable, binary, etc.) named 'pre-commit' (for which
# this file is a template), with the following ordered arguments:
#
#   [1] REPOS-PATH   (the path to this repository)
#   [2] TXN-NAME     (the name of the txn about to be committed)
#
# The default working directory for the invocation is undefined, so
# the program should set one explicitly if it cares.
#
# If the hook program exits with success, the txn is committed; but
# if it exits with failure (non-zero), the txn is aborted, no commit
# takes place, and STDERR is returned to the client.   The hook
# program can use the 'svnlook' utility to help it examine the txn.
#
# On a Unix system, the normal procedure is to have 'pre-commit'
# invoke other programs to do the real work, though it may do the
# work itself too.