Tuesday, 8 March 2011

How to automatically run checkpatch.pl when developing QEMU

The checkpatch.pl script was recently added to qemu.git as a way to scan patches for coding standard violations. You can automatically run checkpatch.pl when committing changes to git and abort if there are violations:

$ cd qemu
$ cat >.git/hooks/pre-commit
#!/bin/bash
exec git diff --cached | scripts/checkpatch.pl --no-signoff -q -
^D
$ chmod 755 .git/hooks/pre-commit

Any commit that violates the coding standard as checked by checkpatch.pl will be aborted. I am running with this git hook now and will post any tweaks I make to it.

Update: If you encounter a false positive because checkpatch.pl is complaining about code you didn't touch, use git commit --no-verify to override the pre-commit hook. Use this trick sparingly :-).

3 comments:

  1. How did you manage to force commit if messages are false positive?

    ReplyDelete
    Replies
    1. I have updated the post to mention the git commit --no-verify option which lets you override the pre-commit hook. This is the solution you are looking for.

      Delete
  2. I did a post on my site based on your article.

    I tried to keep the source material and mention that I based on his work, the purpose of my post is to record the steps needed for those who are beginning to study the QEMU to become a developer.

    The post is being built according to demand that I have knowledge.
    http://carlosdelfino.eti.br/logicadeprogramacao/Preparando_o_Ambiente_Para_Estudar_o_QEMU/

    ReplyDelete