Enforcing coding style with pre-receive Git hook

I am working on an embedded Linux project with a small team, and we have decided to enforce a C coding style. We have chosen the Linux Kernel coding style, and we use the script provided in the Kernel tree checkpatch.pl to check our patches.

We would like to check the coding style before accepting a patch on the server, using a pre-receive hook. However, we cannot find a reliable script that does this job, specially when branches are created and deleted.

  • C++ Jenkins QA Stack / Tools
  • how to implement git id or build to c# application
  • Git commit and push a binary file, but don't keep history
  • Download code from GitHub using octokit.net
  • Error on creating new Git project in Visual Studio 2013
  • How can i get access to the SVN pre-commit message using SharpSVN?
  • May we solve this problem via Git remote hooks? Specifically, we need to check all the modified files by a commit (or series of commit) with checkpatch.pl.

  • Git asking for password.
  • What happens when you create a git branch and then remove the previous commit?
  • Why does git status for a particular repo return paths relative to the root instead of the current directory?
  • Best practice to store .jar files in VCS (SVN, Git, …)
  • Magento's SUPEE-6788 patch not working with Git/Github
  • Connect to the database in a Heroku node.js app without revealing authentication details on git
  • One Solution collect form web for “Enforcing coding style with pre-receive Git hook”

    You can see in this gist an example of detection of branches being deleted or created

    case "$refname" in
        branch=$(expr "$refname" : "refs/heads/\(.*\)")
          if [ 0 -ne $(expr "$newrev" : "0*$") ]; then # deleting
          else #updating
            if [ 0 -ne $(expr "$oldrev" : "0*$") ]; then # pushing a new branch

    You should be to adapt that in order to manage your coding style check.

    Git Baby is a git and github fan, let's start git clone.