Automatically apply patches from Django’s (or any) Trac¶

Lately I’ve been delving into Django development a bit more, and applying people’s patches has been a bit of a hassle. You know you want to apply someones patch, but there are about five steps in between you and applying their patch to your source tree.

So I’d like to present trac_patch.py, which allows you to apply a patch from Django’s trac automatically. It is posted on github, so I encourage everyone to fork it and modify it to fit your own workflow. This was done in about 2 hours, so it’s still pretty rough. Also note, that this should work with a small modification on just about any trac install out there.

I threw a few features in that were useful for my development workflow. You can easily create a new git branch automatically with the name of the patch that you’re applying. You can apply and revert a patch. It also has a mode where you can confirm the ticket you’re looking at, and choose which of the patches on the ticket you wish to apply to your code.

You can use it by default if you’re in your current top-level django directory (or where ever you want the patches applied). However, there is a django_src variable in the code that you can set and then it will work from anywhere.

I’ll paste in the modules docstring below, so you see some examples of it in action.