Exchanging Work in Progress with Mercurial

The Problem

I work with other people on software projects. Sometimes it would be really handy to be able to exchange unstable work in progress with other developers, without having to commit the work as a permanent changeset in our version control repository.

My Solution

I’ve written a Mercurial extension that lets you do just that. Here’s the intended workflow:

  1. You do some work in your repository. You want to share it, but it’s not ready to commit.
  2. You type hg draft , which stores your work in a draft changeset.
  3. You push your draft changeset to your collaborators.
  4. You do some more work, and type  hg draft  again. This amends the previous draft changeset.
  5. You push the new draft to your collaborators.
  6. When you’re ready, you type  hg commit  as usual, and it replaces the draft changeset with a real one.

Get the Code

I’ve published my code at https://bitbucket.org/talljosh/tallhg but before you start using it, there is one caveat: for this extension to work as described above, you need to set up your repository so that changes to history can propagate between repositories. This means you must:

  • enable the (incredibly cool) evolve extension
  • set up your repository to be non-publishing by adding the following snippet to your repository’s  .hg/hgrc  file:
    [phases]
    publish = False

To use my extension, simply get the code:

hg clone ssh://hg@bitbucket.org/talljosh/tallhg

Then enable it in your  .hgrc  file.

[extensions]
draft = /path/to/tallhg/hgext/draft.py

My extension has been tested with mercurial 2.8.2.

How it Works

This extension works by storing metadata which marks your draft commits as work in progress. When further commits are added, this metadata is detected, and the new commit amends the old one.

A Caution

I’ve called the commits this extension creates “draft commits”, but this is very different from the commits being draft phase commits. I realise that this could cause confusion, but I couldn’t think of a better description of what this extension does. If you think of one, please let me know!

This entry was posted in midlength and tagged , , , , . Bookmark the permalink.

Comments are closed.