Archive for October, 2008

Showing the Git branch in your bash prompt

Wednesday, October 29th, 2008

Safe and Secure - Image by frko: http://www.sxc.hu/photo/962334

Safe and Secure - Image by frko: http://www.sxc.hu/photo/962334

My first adventure in source control was many years ago. It was my first proper job and I was the sole developer in a tiny company. To keep the source code safe, it was all stored on a network share, and the file server was backed up at least once a day.

The problems started when two other developers joined the team. Within a week we repeatedly had the issue of two people editing the same file at the same time and one of them losing their changes. So we devised our own source control system. Every file had a piece of cardboard with its name written on it, about 2cm by 10cm. These were stuck, with blu-tak, to a wall. If anyone wanted to edit a file they must stand up, go to the board, take the piece of cardboard for that particular file and stick it to their monitor. So we had an at a glance view of who was working on what and also made sure that the files were kept safe.

Since then I’ve used Visual Sourcesafe (don’t laugh). To my mind, it’s not completely awful, but I could never get my head around branching and merging. I then moved to Subversion which is both incredibly simple to use and free. And I understood branching and merging, but it was just a bit too long-winded to use.

However now I, like all the Rails-kids, use git. Which is both great and awful. It’s taken me weeks to even begin to get my head around it. I still lose code every now and then. But it’s so easy to branch and merge; for the first time, branching is an integral part of the way I work. There is danger in branching though. With svn it’s easy to see which branch you are in – it’s the folder name. In git, it’s not so easy.

So, my extremely smart colleague, David Smalley, showed me this amendment to your .bashrc (or in my case .profile):

function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}

export PS1="\u@\h:\w\$(parse_git_branch)\$ "

The function asks git which branch we are currently in. We then set PS1, the variable for the command prompt, asking it to show the username, host, path and branch.

So, if you are not in a git-managed folder you see:

rahoulb@monster:/Volumes/src$

And if you are in a git-managed folder you see:

rahoulb@monster:/Volumes/src/bb-billing(master)$

So now you have no excuse!

Photo by frko

Working for Brightbox

Thursday, October 16th, 2008

 

Brightbox Messages between myself and John Leach

Brightbox Messages between myself and John Leach

Sometimes you have a moment where you know that you’re on the right path.  

I was hunting through an archive of work done for Brightbox and found this message trail.  I had just tracked down a bug and posted a small screenshot of the fix.  

John’s response let me know that this would be a great place to work.  

Sometimes, it just feels right.

Telling Stories with RSpec

Thursday, October 16th, 2008

Last night I gave a talk at Geekup about RSpec and RSpec User Stories.  

 

Telling Stories With RSpec
View SlideShare presentation or Upload your own. (tags: ruby rails)

 

Thanks to Ashley Moran for talking it through with me.

UPDATED to use Slideshare to display the slides.