Hooks

Craig Ozancin c.ozancin at gmail.com
Sun Mar 14 23:42:47 UTC 2021


I have written my own variant of a space checker.

-   it checks for trailing spaces, tab-characters, and lines that exceed a
    specific length

-   It reads its configuration from the ~/.hgrc or .hg/hgrc under group
[spaces]

-   it reads a local ignore file to identify what file types or names to
    ignore for each of its tests.

-   it report issues found by file/line number

-   it can be run as a mercurial hook with a --hook option or as separate
comman
d.
-   it has an option --clear to automatically removed trailing spaces and
tab-ch
aracters.

It works well and allows me to configure it globally and at the repo level.

The downside is that it takes a minimal of 1 - 1 1/2 seconds to run (more
depend
ing on the number of files changes it must evaluate). A good portion of
this
is the calls to hg (currently 2) to locate the repo root and to get the
list
of files modifications.

In my ~/.hgrc file I have added the following:

   [hooks]
   pretxncommit.whitespaces = ~/bin/spaces --hook

   [alias]
   spaces      = ! ~/bin/spaces "$@"

This is working for me. I haven't accidentally committed a change that
included
a trailing white space in nearly a year using it.

There are a couple annoying side affect that it has due to my use of
pretxncommi
t hook:

1 ) when committing, it does not catch issues until the very end. This is
after
I have edited a change message in vim and saved it. Then it runs the spaces
scri
pt and catches any issues and backs out the commit if it does. I really
want thi
s to be run first.

2 ) it gets run anytime that a changeset is created. On the surface that
seems g
ood, but that happens anytime I rebase or do anything where hg-evolve gets
invol
ved with creating new changesets ad obsoleting others. It really slows down
ever
ything noticeably.

Today I started playing with some of the hook types:

-   precommit - still does not catch issues until the very end. Does not
run spa
ces when doing a rebase or evolve.

-   pre-commit - this catches it at the very beginning and also does not
run spa
ces when doing a rebase or evolve.

Unfortunately, amend and absorb can add content with issues with out spaces
gett
ing called and that is a real problem.

Ideally, it would be nice to be able to create a hook with a set of
parameters s
uch as the command that are are tracked.

Is there anything that does this now? Are there any hooks that world work
better
(I have searched both documentation and online).

Craig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial/attachments/20210314/f74b8a65/attachment.html>


More information about the Mercurial mailing list