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?
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 using pretxncommit
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 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With