[neomutt-devel] clang-format pre-commit hook

Julian Andres Klode jak at jak-linux.org
Sun Jun 25 14:20:00 CEST 2017

On Sun, Jun 25, 2017 at 12:57:51PM +0100, Thomas Adam wrote:
> On Sun, Jun 25, 2017 at 11:37:00AM +0200, Julian Andres Klode wrote:
> > result=0
> > for file in `git diff-index --cached --name-only HEAD | grep '\.[ch]$'` ; do
> You shouldn't need to invoke grep, for instance:
>     for file in $(git diff-index --cached --name-only HEAD -- **/*.[ch]); do

That requires ** support, which I know bash supports, but is disabled by

> Plus, any shell which doesn't support $() in favour of backticks shouldn't e
> supported by definition.

$(command) is the primary standard POSIX version, `command` is a historic
alternative that should not be used anymore.

> >   clang-format  ${file} > ${GIT_DIR}/current_file
> >   colordiff --label "$file (to be committed)" --label "$file (reformatted)" -u ${file} ${GIT_DIR}/current_file || result=1
> colordiff?  You can still use git to give you this information.

Thatt was flatcap's idea. You could use some weird git diff invocation
with GIT_DIR manipulation or something.

> Whilst the idea of this might be useful for some, chances are it's likely to
> get caught through other means; I'd hope when peer-review happens.

It might catch some glaring mistakes like { on the wrong line, but usually
does not catch smaller whitespace issues in my experience. And it's pointless
- any commit will likely have at least one issue, so best to automatize this
locally rather than involving a review roundtrip.

Debian Developer - deb.li/jak | jak-linux.org - free software dev
                  |  Ubuntu Core Developer |
When replying, only quote what is necessary, and write each reply
directly below the part(s) it pertains to ('inline').  Thank you.

More information about the neomutt-devel mailing list