« Incredibly useful SSH flag | Pycon and Euro Djangocon »
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.
Description::
Simple utility to grab and apply a Django trac ticket.
It could in theory be used for any trac installation.
Usage:: trac_patch.py [ticket_num]
-h, --help show this help message and exit
-r, --reverse Reverse the patch
-g, --git Make a git branch
-a, --ask Make a git branch
Examples::
trac_patch.py [ticket_num] [-r]
#Apply patch 6378
trac_patch.py 6378
#Reverse patch 6378
trac_patch.py 6378 -r
#Create a git branch and apply patch
trac_patch.py 6378 -g
#Confirm patch filename and ticket filename
trac_patch.py 6378 -a
Posted at 11:18 p.m. on February 28, 2009
Comments: 4
Tags: django , patch , ticket , tips , trac
Handling Django Settings Files
Finding Missing Indexes That Django Wants (Postgres)
The problem with Django's Template Tags
Welcome to the home of Eric Holscher on the web. I talk about software development, mostly in the realm of Django. I am interested in the real time web, testing, mobile apps, and other things.
Why Read the Docs matters
2 weeks, 1 day ago (Comments: 7)
Read the Docs Update
10 months ago (Comments: 2)
Using Reviewboard with Git
1 year ago (Comments: 0)
Read the Docs Updates
1 year ago (Comments: 1)
Handling Django Settings Files
1 year ago (Comments: 12)
Required Reading
1 year, 2 months ago (Comments: 0)
Using Haystack to index non-database content
1 year, 2 months ago (Comments: 4)
Correct commands to check out and update VCS repos
1 year, 2 months ago (Comments: 0)
Site upgrades
1 year, 2 months ago (Comments: 0)
Building a Django App Server with Chef: Part 4
1 year, 2 months ago (Comments: 1)
Setting up Django and mod_wsgi
Building a Django App Server with Chef: Part 1
Screencast: Django Command Extensions
Big list of Django tips (and some python tips too)
Handling Django Settings Files
Lessons Learned From The Dash: Easy Django Deployment
Large Problems in Django, Mostly Solved: Delayed Execution
Building a Django App Server with Chef: Part 2


Comments
1 lamby says...
Nice idea. I use a similar system based on the Quilt patch tool, and I have also used topgit to do this too. Neither of those take Trac bug numbers as input, but they are much more flexible. Let me know if you want more details.
Posted at 9:54 a.m. on March 1, 2009
2 Eric Florenzano says...
s/give/five/
Posted at 10:57 a.m. on March 1, 2009
3 Brian Rosner says...
Ha! I was thinking about a similar tool just the other day. So glad someone else got to it before me! I am looking forward to trying it out. Thanks Eric!
Posted at 5:03 p.m. on March 1, 2009
4 asdf says...
I am getting this:
python trac_patch.py 2445 Patching file running patch -p0 < /tmp/choices_func_newforms-admin.patch can't find file to patch at input line 5 Perhaps you used the wrong -p or --strip option?
Posted at 11:37 a.m. on July 6, 2009