Wednesday, March 9, 2011

A Git Script for Python

Working on TurboGears, I found myself trying to run all the tests we provide. And then I found myself getting a failure even though I didn't change anything. I had simply switched to a different branch.

Turns out the problem was left over .pyc files. Also turns out that the fix is extremely easy.  In your git repository, create a file named "hooks/post-checkout". In that file, put the following lines, and make the script executable. All .pyc files will be scrubbed every time you switch, preventing the problem entirely.

#!/bin/bash
find . -type f -print | grep -v ^.git | grep '\.pyc$' | xargs rm

No comments: