[FFmpeg-devel] Use the git hooks feature on your PC

James Darnley james.darnley at gmail.com
Sun Oct 12 16:49:58 CEST 2014

Since we have a few newbies on the list with the start of OPW and I've
seen a few other cases recently, I thought this would be a good time to
remind people of the feature of Git called Hooks.

Simply put: a git hook is an appropriately named executable file in the
.git/hook directory in your source tree.  There are several different
ones, each of which gets run at a particular stage when running git

You can find lots of information in git's own help (git help hooks), on
the git website (below), and elsewhere on the Internet.

> http://www.git-scm.com/book/en/Customizing-Git-Git-Hooks

My particular reason for mentioning it now is for spell checking commit
messages and possibly running patcheck.  I don't run patcheck in a hook
but I am considering starting to now.  If someone else has perhaps they
can comment on how useful they found it.  Did it print too many false
positives?  Was it too noisy?  Was it too noisy if you commit often?

I strongly suggest that everyone uses a spell-checker on their commit
messages.  Everyone makes mistakes and since we have many
English-as-a-second-language contributors it can help to pick up on some
common errors.  A while back there was a spree of commits fixing the
word "queue" in the code.  This was easy enough as most the changes were
internal.  What it couldn't do is go back and correct any typos in
commit messages.

I use the following stub in my .git/hooks/post-commit file to check my
commit messages.

> SPELLING=$(git log -n1 --pretty=format:%B | aspell --lang=en-GB list | tr '\n' ' ')
> if [ "${SPELLING}" != "" ]; then
>     echo -e "\x1b[33mYou might want to check the spelling of: ${SPELLING}\x1b[0m"
> fi

A little explanation.

> git log -n1 --pretty=format:%B

Prints the raw, unwrapped subject and body of the commit message for the
last commit.

> aspell --lang=en-GB list

Prints a list of misspelled words.  I use en-GB but if you don't know
the difference, use en-US as I think that is the standard FFmpeg aims for.

> tr '\n' ' '

Translates newlines into spaces.  Mostly for cosmetic and space reasons
because aspell prints one word per line.

> if [ "${SPELLING}" != "" ]

If SPELLING is not empty...  Why print anything if nothing is misspelled?

> echo -e "\x1b[33mYou might want to check the spelling of: ${SPELLING}\x1b[0m"

Print a message for me to see, including the misspelled words, and
highlight it in yellow.  I highlight it because git commit can print a
few other things.

Finally, I will add that I use post-commit because I don't want the
spellcheck to block commits just because I use the word "ffmpeg",
"libavcodec", or some common tech-related abbreviation.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 603 bytes
Desc: OpenPGP digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20141012/1bb2e86f/attachment.asc>

More information about the ffmpeg-devel mailing list