Thursday, March 15, 2012

Unshelving with Merge Conflicts

My team at work uses mercurial for source control. One of the concepts in the mercurial is a “shelf” where you can place partially completed work while you take care of synchronizing your local repository with another repository. You don’t always have to place items on the shelf, but some operations in mercurial require a clean local repository.

A coworker recently placed some items on his shelf and then synchronized his repository. When he went to “unshelve” his changes, there was a conflict. The (redacted) error text read “Unshelve Abort patching file <filename.ext> Hunk #<number> FAILED at <number> <number> out of <number> hunks FAILED – saving rejects to file <filename.ext>.rej”. He had been working on one of the files that had also been updated during the synchronize. Technically, the original shelving operation was unnecessary as mercurial is intelligent enough to merge conflicting files. The shelving was done, however, and he still needed his changes that were on the shelf.

The ultimate solution was the revert the repository back to the point of the shelving, then proceed with the synchronization without shelving.

There may be another way to tell the shelf that the conflicts have been resolved and it can continue (like with hg transplant --continue). If you know of a way to do this, feel free to let me know.