帮助使用 subversion (svn) 挂钩脚本

发布于 2024-08-15 16:48:32 字数 272 浏览 4 评论 0原文

如何创建一个颠覆服务器挂钩脚本,以防止人们在不首先拥有文件锁的情况下提交更改?

svn服务器是在windows上的。

谢谢。

PS 此问题中的附加信息

Subversion (svn + tortoiseSvn) 提交未锁定文件

How to create a subversion server hook script that prevents people from committing changes if they don't own the lock on the file first?

Svn server is on windows.

Thanks.

P.S. Additional info in this question

Subversion (svn + tortoiseSvn) commit not locked file

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浮云落日 2024-08-22 16:48:32

使用预提交挂钩。预提交挂钩接收 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作为循环项)并确定 svn:needs-lock,以及它们当前是否被锁定:

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

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

Use a pre-commit hook. Pre-commit hook receives 2 arguments:

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

You need to use svnlook to determine if there are svn:needs-lock files that aren't locked.

To determine the paths changed by this commit:

svnlook changed $1 --transaction $2

Loop through the files ($PATH as loop item) in 'changed' and determine svn:needs-lock, and if they're currently locked:

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

Write an to stderr and return non-zero to abort this commit when needed.

↙温凉少女 2024-08-22 16:48:32

您可以使用<您的存储库目录>/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.

You can use <your repos directory>/hooks/pre-commit and use some batch scripting (or even a full blown program, as long as it's executable it will be fine). If it returns 0 the commit will be successful; otherwise it will fail.

See post-lock.tmpl in that same directory for an example.

# 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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文