← Back to team overview

kicad-developers team mailing list archive

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

 

Hey John,

This looks good to me.  If no one else objects, I will merge it.

Cheers,

Wayne

On 10/22/2018 1:29 PM, John Beard wrote:
> Hi Wayne,
> 
> If you have git-clang-format installed (you will do if you have clang on
> Arch, for example), you can just run `git clang-format --diff` to see
> violations in the uncommitted changes (according to the `_clang-format`
> file). This is already possible, though you *should* still set `git
> config clangFormat.style file` to ensure it uses the KiCad
> `_clang-format` file.
> 
> I have added a env var switch to the format pre-commit hook. If you set
> `KICAD_CHECK_FORMAT` to something in the shell, it will run the check.
> Then the default action is "do not check at all" (as the var is not
> set). Developers can then add to shell configs and/or set/unset/export
> as they need.
> 
> We can use the same technique to selectively enable other hooks in future.
> 
> Documentation also updated.
> 
> Cheers,
> 
> John
> 
> On 22 October 2018 17:50:41 BST, Wayne Stambaugh <stambaughw@xxxxxxxxx
> <mailto:stambaughw@xxxxxxxxx>> wrote:
> 
>     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
>         <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>
>         Unsubscribe : https://launchpad.net/~kicad-developers
>         More help : https://help.launchpad.net/ListHelp
> 
>     ------------------------------------------------------------------------
>     Mailing list: https://launchpad.net/~kicad-developers
>     Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx <mailto:kicad-developers@xxxxxxxxxxxxxxxxxxx>
>     Unsubscribe : https://launchpad.net/~kicad-developers
>     More help   : https://help.launchpad.net/ListHelp
> 


References