您如何访问 Mercurial 进程内挂钩中的提交消息? [英] How do you access the commit message in a Mercurial in-process hook?

查看:31
本文介绍了您如何访问 Mercurial 进程内挂钩中的提交消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力

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?

推荐答案

事实证明,我最初的方法有两个问题:

It turns out there are two things wrong with my initial approach:

  1. 正如 jk 所指出的,precommit 事件发生在提交之前,因此正在处理的提交的元数据尚不存在.通过使用 pretxncommit 代替,元数据存在,但事务尚未提交到数据库.
  2. 使用 changectx = repo[None] 为您提供工作目录的更改上下文.但是我们想要当前提交的信息,因此使用 changectx = repo['tip'] 代替为我们提供最新的元数据.
  1. As jk pointed out, the precommit event happens before the commit so the meta data for the commit being processed doesn't exist yet. By using pretxncommit instead, the meta data exists, but the transaction hasn't been committed to the database yet.
  2. Using changectx = repo[None] gives you the change context for the working directory. But we want the info for the current commit so using changectx = repo['tip'] instead gives us the most recent meta data.

请注意,如果您将 changectx = repo['tip']precommit 事件一起使用,您实际上会得到处理的最后一次提交,而不是您当前的提交正在努力.

Note that if you use changectx = repo['tip'] with the precommit event, you'll actually get the last commit processed, not the current one you are working on.

这篇关于您如何访问 Mercurial 进程内挂钩中的提交消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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