How do you access the commit message in a Mercurial in-process hook?

房东的猫 提交于 2019-12-07 03:09:52

问题


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?


回答1:


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

  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.

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.




回答2:


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.



来源:https://stackoverflow.com/questions/2451560/how-do-you-access-the-commit-message-in-a-mercurial-in-process-hook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!