Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 238
davidavr Avatar asked Mar 16 '10 01:03

davidavr


2 Answers

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.

like image 158
davidavr Avatar answered Sep 22 '22 12:09

davidavr


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.

like image 45
jk. Avatar answered Sep 21 '22 12:09

jk.