Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doing without partial commits the "Mercurial way"

Tags:

dvcs

mercurial

Subversion shop considering switching to Mercurial, trying to figure out in advance what all the complaints from developers are going to be. There's one fairly common use case here that I can't see how to handle.

  1. I'm working on some largish feature, and I have a significant part of the code -- or possibly several significant parts of the code -- in pieces all over the garage floor, totally unsuitable for checkin, maybe not even compiling.
  2. An urgent bugfix request comes in. The fix is nice and local and doesn't touch any of the code I've been working on.
  3. I make the fix in my working copy.

Now what?

I've looked at "Mercurial cherry picking changes for commit" and "best practices in mercurial: branch vs. clone, and partial merges?" and all the suggestions seem to be extensions of varying complexity, from Record and Shelve to Queues.

The fact that there apparently isn't any core functionality for this makes me suspect that in some sense this working style is Doing It Wrong. What would a Mercurial-like solution to this use case look like?


Edited to add: git, by contrast, seems designed for this workflow: git add the bugfix files, don't git add anything else (or git reset HEAD anything you might have already added), git commit.

like image 517
David Moles Avatar asked Jun 10 '10 08:06

David Moles


2 Answers

Here's how I would handle the case:

  1. have a dev branch
  2. have feature branches
  3. have a personal branch
  4. have a stable branch.

In your scenario, I would be committing frequently to my branch off the feature branch.

When the request came in, I would hg up -r XYZ where XYZ is the rev number that they are running, then branch a new feature branch off of that(or up branchname, whatever).

Perform work, then merge into the stable branch after the work is tested.

Switch back to my work and merge up from the top feature branch commit node, thus integrating the two streams of effort.

like image 50
Paul Nathan Avatar answered Oct 09 '22 02:10

Paul Nathan


Lots of useful functionality for Mercurial is provided in the form of extensions -- don't be afraid to use them.

As for your question, record provides what you call partial commits (it allows you to select which hunks of changes you want to commit). On the other hand, shelve allows to temporarily make your working copy clean, while keeping the changes locally. Once you commit the bug fix, you can unshelve the changes and continue working.

The canonical way to go around this (i.e. using only core) would probably be to make a clone (note that local clones are cheap as hardlinks are created instead of copies).

like image 38
avakar Avatar answered Oct 09 '22 03:10

avakar