如何修改预提交挂钩中的提交消息?

How to modify commit message in pre-commit hook?

Server side hook scripts
Set up svnperms pre-commit hook
Use the commit message in a CVS pre-commit hook

我正在通过从项目中提取几个库来重构项目。这些库被移动到不同的存储库并通过 svn:external.

检出

问题是提交到中央存储库无法再解释提交时的系统状态。最初,我通过手动向每个提交 Tested with libA:revXXXX, libB:revYYYY, libZ:revZZZZ. 添加一行来解决这个问题。当然,一旦我的同事加入该项目,这将是不可接受的,而且这些库开始用于新项目。

自动执行此操作的正确方法是什么,即 在每次提交时,检查所有 svn:extern 依赖项的最新版本 trunk 并将该信息附加到提交消息中?

如果可能的话,您不应该在预提交挂钩中执行此操作。 SVN book 表示:

While hook scripts can do almost anything, there is one dimension in which hook script authors should show restraint: do not modify a commit transaction using hook scripts. While it might be tempting to use hook scripts to automatically correct errors, shortcomings, or policy violations present in the files being committed, doing so can cause problems. Subversion keeps client-side caches of certain bits of repository data, and if you change a commit transaction in this way, those caches become indetectably stale. This inconsistency can lead to surprising and unexpected behavior. Instead of modifying the transaction, you should simply validate the transaction in the pre-commit hook and reject the commit if it does not meet the desired requirements. As a bonus, your users will learn the value of careful, compliance-minded work habits.

如果你不想手动包含你的提交注释,你总是可以编写一个包装 svn commit 的脚本并让每个人都使用它。

但是......为什么你的提交消息中需要这个?您正在使用 svn:externals,如果使用得当,它已经记录了所使用的版本。您 正确地使用它们并进行了明确的修改,不是吗?