Search code examples
gitcoding-styleuncrustify

Ensure coding-style during a git commit


Im my company i set-up a continuous integration test and i run the tests when someone push the code on the server.

Now i want to check that the code match with the our basic coding rules, the first rule is "run mogrify on your code!"

There is something to do this check "out the shelf"? the output of this analisys can be stored on a file or something else.

thanks


Solution

  • I would suggest using a lint like tool, e.g. for ObjectC you could use oclint, but basically any coding standard verification tool that can output to either text files or to stdout - you can then use a python script, (since python is one of the default languages for hooks), or almost any thing that can parse that output, and compare it to a given benchmark then return 0 if the code is no worse than before and 1 if it is.

    This can then be used as a hook, either pre-commit locally or pre-receive on the server, (or even both).

    Alternatively if you are concerned about the developer having actually run a given tool you can always put a wrapper around the tool that saves, as a part of the committed code, something like an MD5 of the code at the point that the tool was last run and you can write a pre-commit/receive hook that checks that the MD5/whatever of that file matches that of the committed code.