Something-driven development

Software development thoughts around Ubuntu, Python, Golang and other tools

Sharing your development environment across branches

with 5 comments

If you’re working on a project that bootstraps a development environment (using virtualenv or similar) it can be painful to bootstrap the environment for every bug/feature branch that you work on. There are lots of ways you can avoid this (local cache etc.), but if you’re using bzr to manage your branches, a single working directory for all your branches can solve the problem for you. Most bzr users will be familiar with this, but people new to bzr might benefit.

The one-time setup is pretty straight forward – create a repository with a local copy of trunk, and a branch of trunk for your new feature/bug:

$ cd dev/
$ bzr init-repo myproject
$ cd myproject
$ bzr branch lp:myproject trunk
$ bzr branch trunk myfeaturex

From now on, you can simply `cd trunk && bzr pull` when you want to update your local trunk [1]. Now we’ll create a light-weight checkout and bootstrap our environment there. I tend to call this directory ‘current_work’ but whatever works for you. Also, most of the projects I’m working on are using fabric for setting up the virtualenv and other tidbits, but replace that with your own bootstrap command:

$ bzr checkout --lightweight myfeaturex current_work
$ cd current_work && fab bootstrap

Assuming everything went well, you now have your development environment setup and are ready to work on myfeaturex. Make changes, commit etc., push to launchpad – it’ll all be for your myfeaturex branch. But what if half-way through, you need to switch and work on an urgent bug? Easy: commit (or shelve) any changes you’ve got for your current branch, then:

$ cd ..
$ bzr branch trunk criticalbugx
$ cd current_work
$ bzr switch ../criticalbugx  [2]

Edit 2011-05-23: See Ricardo’s comment – the above 4 lines can be replaced by his two.

That’s it – your current_work directory now reflects the criticalbugx branch – and is already bootstrapped [3], you can work away, commit push etc., and then switch back to your original branch with:

$ bzr switch ../myfeaturex

If you’re working on large branches, once you’ve got the above workflow, you may want to try next keeping large features reviewable with bzr pipelines.

[1] It’s a good idea to never do any work in your trunk tree… always work in a branch of trunk.
[2] The ../ is not actually required, but when you’ve lots of branches with long names, it means you can tab-complete the branch name.
[3] Of course, if one of your branches changes any virtualenv requirements or similar, you’ll need to re-bootstrap, but that isn’t so often in practise. Or sometimes a new version of a dependency is released and you won’t get it until you rebootstrap.

About these ads

Written by Michael

May 19, 2011 at 3:17 pm

Posted in bzr, python

5 Responses

Subscribe to comments with RSS.

  1. Just a small shortcut to the workflow. Instead of having to do

    cd ..
    bzr branch trunk criticalbugx
    cd current_work
    bzr switch ../criticalbugx

    you can all of this with

    bzr switch trunk
    bzr switch -b criticalbugx

    This will switch to trunk first, so that the next step behaves correctly. The -b argument to switch will create a new branch and switch to it. The branch will be created as a child of the currently active branch (that’s why we first switch to trunk).

    Thanks for the post!

    Ricardo Kirkner

    May 23, 2011 at 4:01 pm

  2. Nice – thanks Ricardo… I’ll update the post.

    Michael

    May 23, 2011 at 5:45 pm

  3. [...] Sharing your development environment across branches (micknelson.wordpress.com) [...]

  4. [...] you’ve already got a lightweight checkout of your project code, create a new branch for part-1 of your feature and switch to [...]

  5. [...] Sharing your development environment across branches (micknelson.wordpress.com) [...]


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.

Join 87 other followers

%d bloggers like this: