Firing up a new project in 5 secs

September 8, 2011

I’m running Gitosis on my home Linux server. I like to keep everything under source control, and this setup allows me to have dozens of small projects with very little overhead.

This is really convenient, except every time I start a new project I have to

  • Add it to gitosis-admin, commit and push
  • Set up the initial Git repo for the project
  • Touch, add and commit a README
  • Setup the remote
  • Do the inital push with “-u”

Obviously, this gets pretty tedious, so I automated it with the following script.

#!/bin/bash

PROJECT=$1
THIS_SCRIPT=`readlink $0`
GITOSIS_ADMIN_DIR=${THIS_SCRIPT%/*/*}
GIT_SERVER=chopmo.dk

echo "Project:" $PROJECT
echo "Gitosis admin is at $GITOSIS_ADMIN_DIR"
echo "Adding project to gitosis-admin"
cd $GITOSIS_ADMIN_DIR
sed -i "" "/just-me/,\$s/writable.*/& $PROJECT/" gitosis.conf
git add gitosis.conf
git ci -m "Adding new project $PROJECT"
git push

echo "Setting up local repo"
mkdir $PROJECT
cd $PROJECT
git init
touch README
git add README 
git ci -m "initial commit"
git remote add origin git@$GIT_SERVER:$PROJECT.git
git push -u origin master

echo "Done."

It is stored under “bin” in my gitosis-admin repo and symlinked to ~/bin/new_project (which is why the readlink at the top is important).

The “sed” call appends the new project name to the list of projects which are writable by only me. The just-me,$ addresses are necessary because the structure of my gitosis.conf is:

[gitosis]

[group gitosis-admin]
writable = gitosis-admin
members = ...

[group just-me]
writable = foo bar baz ...

members = ...

So without the limiting addresses, I would append the new project to the writable projects in the gitosis-admin group as well.

My bash skills are pretty weak, so feedback on the script would be very welcome. But this works, and it means that the amount of time from I get an idea for a new project until I can start hacking on it is brought down to just a few seconds.

 

About these ads

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: