Project

General

Profile

Automate a checkpatch run on commit » History » Version 1

Sergey Smolov, 12/17/2019 10:55 AM

1 1 Sergey Smolov
h1. Automate a checkpatch run on commit
2
3
h2. Copyright
4
5
The material has been taken from "here":http://blog.vmsplice.net/2011/03/how-to-automatically-run-checkpatchpl.html (author is Stefan Hajnoczi).
6
7
h2. How to automatically run checkpatch.pl when developing QEMU
8
9
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:
10
<pre><code class="shell">
11
$ cd qemu
12
$ cat >.git/hooks/pre-commit
13
#!/bin/bash
14
exec git diff --cached | scripts/checkpatch.pl --no-signoff -q -
15
^D
16
$ chmod 755 .git/hooks/pre-commit
17
</code></pre>
18
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.
19
_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 :-).