Mercurial pretxncommit hook - act only on commit, ignore rebase and patch
Asked Answered
B

1

11

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
Borneol answered 23/7, 2018 at 8:49 Comment(1)
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.Borneol

© 2022 - 2024 — McMap. All rights reserved.