Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ensure coding-style during a git commit [closed]

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

like image 586
TheObjCGuy Avatar asked Dec 02 '13 22:12

TheObjCGuy


People also ask

Should you commit unfinished code?

Noting the 'working code' is part of the 'dev' branch policy, one should never commit broken code to the dev branch. Often there are things such as CI servers hooked up to these branches and checking in broken code into dev could mess up everyone's branch and break the build.

What should a commit message look like?

General Commit Message Guidelines As a general rule, your messages should start with a single line that's no more than about 50 characters and that describes the changeset concisely, followed by a blank line, followed by a more detailed explanation.


1 Answers

During a git commit, you could ask your users to setup a pre-commit hook which could run the test, and block the commit.

But you don't have a guarantee that your users actually follow that policy (or bypass it with a git commit --no-verify).

So you should rather put a pre-receive hook in your central repository (the one where all developers are pushing), in order to reject the push if you detect that your tool hasn't been properly run.

See Git Hooks.

Regarding tools, uncrustify can be set as a pre-commit hook, but that can be a bit slow. But it has been used that way before.
Alternatives are listed in this thread but seem quite obsolete.

Your idea to apply on the server side could work, as a pre-receive hook (meaning you would reject the push if you detect differences between the code pushed and the same code received and "uncrustified").

like image 91
VonC Avatar answered Nov 02 '22 01:11

VonC