如何访问 Mercurial 进程内挂钩中的提交消息?
我一直在尝试
def debug_hook(ui, repo, **kwargs):
changectx = repo[None]
ui.status('change.desc: %s\n' % changectx.description())
return True
但它总是打印一个空字符串。这是因为它是预提交挂钩并且消息尚不可用吗?或者我只是错过了一些明显的东西?
I've been trying
def debug_hook(ui, repo, **kwargs):
changectx = repo[None]
ui.status('change.desc: %s\n' % changectx.description())
return True
But it always prints an empty string. Is this because it is a precommit hook and the message isn't available yet? Or am I just missing something obvious?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,我最初的方法有两个问题:
预提交
事件发生在提交之前,因此正在处理的提交的元数据不会发生。还不存在。通过使用pretxncommit
,元数据已存在,但事务尚未提交到数据库。changectx = repo[None]
为您提供工作目录的更改上下文。但我们需要当前提交的信息,因此使用changectx = repo['tip']
为我们提供最新的元数据。请注意,如果您将
changectx = repo['tip']
与precommit
事件一起使用,您实际上将获得处理的最后一次提交,而不是当前正在处理的提交。It turns out there are two things wrong with my initial approach:
precommit
event happens before the commit so the meta data for the commit being processed doesn't exist yet. By usingpretxncommit
instead, the meta data exists, but the transaction hasn't been committed to the database yet.changectx = repo[None]
gives you the change context for the working directory. But we want the info for the current commit so usingchangectx = repo['tip']
instead gives us the most recent meta data.Note that if you use
changectx = repo['tip']
with theprecommit
event, you'll actually get the last commit processed, not the current one you are working on.我认为你是对的,在预提交中该消息还不存在。如果您使用 pretxncommit ,它会,但我不能 100% 确定它允许您在此时执行什么操作,因为事务即将完成。
I think you are right that in precommit the message doesn't exist yet. if you use pretxncommit it will, but i'm not 100% sure what it allows you to do at that point as the transaction is almost complete.