10

We are using pretxncommit hook for HG to run a quick static analysis check on code commited. However the hook is triggered on applying any changes to commit tree - which includes rebasing and using MQ to edit and squash commits.

Is it possible to somehow check what type of change is happening in hook itself? Like

def analyze_hook(ui, repo, node=None, **kwargs):
    if repo.state.is_commit_added and not (repo.state.is_rebase or repo.state.is_patch):
        return 0
Artalus
  • 1,114
  • 12
  • 25
  • It is possible to `from mercurial.cmdutil import _getrepostate` and check `_getrepostate(repo) is not None` to check if the repo is _currently_ in process of rebase or graft. It prevents hook from acting on merge conflicts, but it still acts once rebase or graft or MQ move is finished. – Artalus Aug 13 '18 at 11:58

1 Answers1

0

you'd want to check the HG_SOURCE to see what operation is bringing you those commits

https://book.mercurial-scm.org/read/hook.html#sources-of-changesets

e.g. https://github.com/vmg/hg-stable/blob/master/tests/test-hook.t

e.g. https://stackoverflow.com/a/11105493/1681985

arhak
  • 2,488
  • 1
  • 24
  • 38