Can’t Push Mercurial Changes into Subversion

I’ve been using Mercurial (Hg) as a method of working offline from a central Subversion (SVN) server. Up until last week it was working perfectly. All of the sudden I couldn’t push changes from Hg back into SVN and I didn’t know why.

I installed TortiseHG and I was using hgsubversion to communicate with SVN. The basic workflow once you do the initial checkout is pretty easy:

hg pull
hg rebase --svn
hg push

I was happy and everything was working smoothly until I got an error: Could not push revision b4590bc6ef0b because it had no changes in svn. I took a look at the changset using HgWorkbench and it was empty. I tried a bunch of things but I couldn’t solve the problem or understand why I had an empty changeset. After about an hour of trying I eventually gave up and asked the hgsubversion mailing list for help.

Dennis Clark had the following answer:

Empty changesets in your Hg repository are not unusual when using hgsubversion. This is because Subversion tracks directory changes but Mercurial does not. If a SVN commit pulled by hgsubversion only contains directory adds and deletes, it ends up as an empty changeset in Hg. This has happened to me and has not been a problem so far.

Fortunately for me he also had a solution which involved removing the offending changeset:

Whenever I’ve had to rewrite the history of a Hg branch (e.g. drop changesets) I’ve found the histedit extension to be quite handy. I find it much easier than mq for doing this kind of thing. It doesn’t hook into the TortoiseHg interface but is fairly simple to use: just make sure that your hg config has ui.editor set to something you know how to use.

So I tried it on a copy of the SVN server and it worked great and let me push my changes from a copy of my mercurial repository. Later I tried to sync my real mercurial repository to the real SVN server and something weird happened: the offending changeset went away after I had pulled all the recent changes and rebased everything. At least I know how to fix the issue next time it happens and I thought I would spread the help around.