Git and the Plone Collective

I have been reading a lot of good things lately about git, and decided to give it a try. I like git, and after some looking into git-svn, was able to work with local repositories with only a few minor mishaps.

I have been working on the Vice project this week, and all was well for a while. Then, one day, I started getting an error when trying to git-svn dcommit my code back into the svn repository. It said that my code contained a pdb.set_trace() statement. This is something that is set in the Plone collective, they just don’t allow commits of this statement anymore, even if they are commented out. I grepped through my code and was not able to find any pdb statements. Looking through the rest of the code, I fought with this for a while. I then remembered that git pushes it’s commit history to svn, and I had had some pdb statements in my code that I had since removed. So, the problem was way back in my history.

I suppose that I could have dug through git and tried to alter my history to no longer include this code, but I have only been using git for a few weeks and was worried about trashing it. My short-term fix was to do a new svn checkout, move my new code over there, and commit that. I know it’s bad, but I just don’t have the time that it would take to try to figure out how to alter my history.

I want to keep using git, so I needed a way to have git itself check for the statement, and disallow a commit if I forgot about a pdb statement. With no clue as to how to go about this, I tried #git on freenode. The people on that channel were very nice, and jast pointed me to the pre-commit hook in .git/hooks/pre-commit, noting that there was a sample in there.

Open up this file and look for the lines of Perl. There are a bunch of if regex statements at the bottom that go along the pattern “if (/\s$/){“. I added my own check, which looks like this:

if (/pdb.set_trace()/){
    bad_line("pdb.set_trace() found", $_);

You have to make the file executable in order for it to be run, so chmod +x pre-commit before you test this out. After making the change, I went into one of my files and added a pdb statement, git correctly found it and refused to allow the commit, letting me know the filename and line number where the statement was found, which is more than the svn error ever gave me.


~ by Liz on May 2, 2008.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: