views:

493

answers:

3

I am trying to contribute to a project that uses Subversion. I used Mercurial and its hgsubversion extension to clone the repo. My work takes place on a feature branch.

How do I keep the feature branch up to date with stuff that happens on the default branch (hg speak) aka the trunk (svn speak)?

So I used hg up feature to update to the feature branch, then hg pull which gave me changesets on the default branch. So I did hg merge default, the committed the merge, then tried hg push to send my changesets to Subversion. And Mercurial said: "Sorry, can't find svn parent of a merge revision."

A: 

Mercurial as a few different branching modes: http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial/

The one you're describing is 'named branches', which is the most popular when you're working with a repo that's accessed only via mercurial (or hg-git).

However, when you're using hg-subversion so that you're pushing changes to/from subversion, which only nominally has branches, you're better off keeping all of your mercurial changes in the 'default' named branch, and using the 'clones and branches' pattern (which I prefer anyway).

Specifically, that message Sorry, can't find svn parent of a merge revision. isn't a descendant of a revision that has a direct match in subversion.

Were I you, I'd reclone from svn, and then move my work into that repo's 'default' branch with the 'transplant' command (packaged extension). If you want multiple features in parallel w/ hg-subversion use separate clones (they're so cheap), as it's more in line with how subversion thinks about branches.

Ry4an
Thanks, Ryan.But with your suggestion, my work will not appear upstream (i.e. in Subversion). I wanted to be able to commit to the Subversion branch. Actually, I can commit to the Subversion branch, but I can't merge from trunk in Mercurial.(And how does Subversion "only nominally" have branches? It seems the support for merging branches in Subversion is weaker than in Mercurial, but it's not too terrible. At least I can fork a branch off of trunk then repeatedly merge from trunk easily and conveniently. The problem comes when I want to reintegrate the branch into the trunk.)
I must've been unclear in my suggestion, as nothing in it precludes you pushing upstream. I'm just suggesting that once you get the changesets into mercurial you limit yourself to a single named branch, as the normal merging back and forth between mercurial branches would preclude you pushing to subversion (as you've seen). Keep all your csets on the same named branch in mercurial land, using multiple clones if you want separate development tracks, and you should be just fine.
Ry4an
Thank you once again, Ryan. How do I work with multiple *Subversion* branches, then?Please note that I did an `hg merge` of two branches existing in Subversion, then wanted to push the merge back to Subversion. Pushing the merge failed with the above error message. Had I done the same merge on the Subversion side, the merge would have arrived intact on the Mercurial side (after `hg pull`).
I'm afraid you've got me there. I've not used hg-subversion against anything except a remote repo's trunk.
Ry4an
+1  A: 

I needed to figure this out for myself and wrote it up here:

http://notebook.3gfp.com/2010/05/pushing-a-new-feature-from-a-mercurial-repo-into-an-svn-repo/

I haven't yet figured out how to close a branch in subversion and have the mercurial graph look correct.

Harvey
Hi Harvey,you are doing the merge on the Subversion side. I would have preferred to merge on the Mercurial side, but if that's not possible, then that's the way it is, I guess. Pity, though.Kai
@hibbelig: yeah, I asked the hgsubversion authors about this and they said that it's an svn limitation because I think they don't have dual "parents" like hg does. That's how hg knows about the merge.
Harvey
A: 

I have finally figured out how to get my repository un-wedged after an event like that described in the question, so that I can continue work without having to re-clone the parent repository (which is, obviously, a quite slow operation when you are pulling from Subversion!). If the "tip" of Subversion outruns you so that you cannot push any more, just make sure that you have the built-in "rebase" extension activated in your Mercurial through a $HOME/.hgrc line like this:

[extensions]
rebase =

And then you should be able to run this command when your repository gets wedged:

$ hg rebase --svn

If I understand this correctly, it dissolves your current branch that has taken you away from Subversion HEAD, and rebuilds it atop the branch "tip" in Mercurial that corresponds to the HEAD in Subversion. From there, you can keep working and successfully do pushes again. It has always worked for me so far; let me know if you run into any problems!

Brandon Craig Rhodes