Git autopush

January 10, 2011

Some of my Git repos are very, very simple. The commits are all on master, no branches in play at all. And the workflow is just as simple as back in the bad old Subversion days: Pull from the repo, commit some stuff, push it.

A good example is the repo I use to store my Project Euler solutions. It is only used by myself and I always want to push after committing.

So I set out to create (and complete within 10 minutes) my least ambitious project so far: A bash script to add “git push” as a post-commit hook in the current Git repo. You can find it on Github, but the business part of it is right here:

#!/bin/sh

HOOKS_FOLDER=.git/hooks
POST_COMMIT=$HOOKS_FOLDER/post-commit

if [ -d $HOOKS_FOLDER ]; then
    if [ -f $POST_COMMIT ]; then
        echo "Post commit hook already exits, please add 'git push' manually in .git/hooks/post-commit"
        exit -1
    fi
    echo "git push" > $POST_COMMIT
    chmod 755 $POST_COMMIT
    exit 0
else
    echo "This command must be run in the root of a Git repository."
    exit -1
fi

Suggestions welcome for improving the script. I think this is the first multiline Bash script I ever wrote, so I expect it to be flawed.

Ah yes, and before you comment: I know that this is not the shiniest of Git workflows, I know that branches are cheap etc. I love all the cool features of Git but sometimes I just don’t need them.

However I do not know if Git already has this functionality built in via some configuration option?

It seems like I’m going to be haunted by my disastrous server upgrade for some time to come.

The server has gitosis installed, which is what I use for serving my private Git repos. Now, when trying to clone a repo (from another computer), I suddenly got a stack trace:

/usr/bin/gitosis-serve:5: UserWarning: Unbuilt egg for setuptools [unknown version] (/usr/lib/python2.6/dist-packages)
  from pkg_resources import load_entry_point
Traceback (most recent call last):
  File "/usr/bin/gitosis-serve", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 2655, in <module>
    working_set.require(__requires__)
  File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 648, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 546, in resolve
    raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: gitosis==0.2
fatal: The remote end hung up unexpectedly

It turns out that this was because Python had been upgraded to 2.6. Fixing it was extremely easy: Re-install gitosis with the current version of Python:

git clone git://eagain.net/gitosis

cd gitosis

sudo python setup.py install

Now I just need to figure out how to fix the charset encoding in my MoinMoin wiki…

For a while now I’ve been working on a Danish forum for Ruby and Rails developers: railsforum.dk. It will be based on the excellent El Dorado “full-stack community web application” by Trevor Turk.

However, I wanted the forum to be in Danish, including menus, system messages etc. Not because Danish Ruby developers don’t understand English, but because I want to emphasize that this is a Danish site for Danish developers.

So I decided to contribute a Danish localization to El Dorado. Quite a work-intensive (read: boring) taks, although it was made a lot easier by another contribution: An almost complete German translation made by a guy called Manfred. So I didn’t have to go through the really boring process of finding all the strings that need to be localized.

Along the way I added a few more features:

  • The option to hide the title and tagline, making the entire header image a link to the front page.
  • A feature to disable tabs on the site. I need this because I want to keep railsforum.dk as simple as possible, and El Dorado has lots of features.
  • Ruby syntax highlighting (incomplete, not yet submitted).

Finally, I rearranged a few items on the front page and added a new “portlet” there after discussing this with Trevor.

Here’s how it looks right now:

Ah yes, and then I had to spend some time untangling my Git repository. Because I am (or was?) such a Git newbie, I had put all my stuff on one branch, making it impossible for Trevor to merge.

It feels really good finally to have made a more significant constribution to an OSS project than the occasional patch or bug report. This has definitely whet my appetite for getting more involved into projects like El Dorado. Also, Github is really an excellent platform for this kind of collaboration – the catchphrase “Social Coding” is spot on.

Follow

Get every new post delivered to your Inbox.