← Back to team overview

kicad-developers team mailing list archive

Re: [PATCH] Add clang-format pre-commit git hook

 

Hey John,

Is there a way to set this up in git where you can run clang-format on
demand rather than using --no-verify to ignore the hook?  I don't know
if I want to force this on developers so it would be nice if it would
only be run when requested.

Cheers,

Wayne

On 10/19/2018 12:30 PM, John Beard wrote:
> Hi,
> 
> This is a patch to add a hook to check formatting for *changed lines
> only* when committing to Git.
> 
> It is good that KiCad has a style, but it is a highly unique one and
> many people will not be used to writing it. Making it easier for
> people to find mistakes without having to waste the maintainers' time
> and their own ping-ponging patches on the mailing list should be the
> aim.
> 
> By using git-clang-format, we can allow style checking on the changes
> only, so we avoid a huge reformat of the whole code-base (which is,
> despite best efforts, highly inconsistent, so there would be many many
> changes).
> 
> Instructions are in the dev docs, but basically:
> 
> * Install `git-clang-format` (comes with the `clang` package on Arch, at least)
> * Enable the hooks: `git config core.hooksPath .githooks`
> * Make sure it uses the right style source: `git config clangFormat.style file`
> 
> Then it should just work - if you try to commit badly-styled code it
> will tell you what it would change if you ran git clang-format on it.
> If you disagree, you can commit anyway with `git commit --no-verify`
> (aka `-n`).
> 
> Also included is a general "hook-chain" implementation for running
> multiple hooks.
> 
> Cheers,
> 
> John
> 
> 
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp
> 


Follow ups

References