如何访问一个水银过程中的钩提交信息? [英] How do you access the commit message in a Mercurial in-process hook?

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

问题描述

我一直在试图

def debug_hook(ui, repo, **kwargs):
    changectx = repo[None]
    ui.status('change.desc: %s\n' % changectx.description())
    return True

但它始终打印一个空字符串。这是因为它是一个precommit钩和信息不可用了吗?或者,我只是缺少明显的东西?

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 =回购[无] 为您提供工作目录中的变化范围内。但是,我们希望在当前的信息提交因此,使用 changectx =回购['尖'] 而不是为我们提供了最新的元数据。

  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 =回购['尖'] 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.

这篇关于如何访问一个水银过程中的钩提交信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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