This is a simple mercurial hook that checks the following filetypes ('.cpp', '.h', '.as', '.abs', '.py') for the following:
- Tabs anywhere in the line
- Trailing whitespace
- Windows line endings (\r\n)
- "MARK_SECURITY_CHANGE" - Looks for this text and warns user as security changes should NOT be checked into the public tamarin-redux repository.
Installing the commit hook
The easiest way to implement the hook is to sync to the tip of tamarin-redux then add the following to your tamarin-redux/.hg/hgrc file (or to ~/.hgrc to implement for all local repos):
[hooks] pretxncommit.commit = python:/path/to/tamarin-redux/utils/hooks/tamarin-commit-hook.py:master_hook
Once added, all commits will run the commit hook.
On every commit to your local repository, the hook will only check for violations in any new / changed code. Any untouched lines of code that violate the check will be ignored. When a violation is found the following will be displayed:
> hg commit -m "change with a tab" Tab(s) found in test/test.txt for rev 1458 (change 53543674b8e6): @@ -65,4 +65,6 @@ +# tab here ^ (n)o, (y)es, (a)llow Tabs for current file Are you sure you want to commit this change? [n]:
Note that the prompt gives you the options to abort the commit (no), allow the tab (or other violation) on that particular line, or allow the violation for all lines in that file.
If you choose to abort the commit, the commit message will be saved to .hg/commit.save. This allows you to reuse the commit message after fixing the issue by using the -l (--logfile) option:
hg commit -l /reporoot/.hg/commit.save
At the moment this is a local-only hook and is not enforced on the server. This may change in the future and be enforced for all checkins.