4

I'm using hggit to export our mercurial repository to git. I'm following the tutorial here: http://arr.gr/blog/2011/10/bitbucket-converting-hg-repositories-to-git/ This however misses all branches that were not merged into default. I guess it's beacuse of the single bookmark (hg bookmark -r default master). Do I need to bookmark each open branch separately? Can hggit somehow pick all open branches (as we have possibly many of those)?

amaidment
  • 6,942
  • 5
  • 52
  • 88
Jan
  • 1,905
  • 17
  • 41
  • Do you synchronize only from Mercurial to Git or also the other way around? For one-way synchronization from Mercurial to Git, I use this patch series: https://groups.google.com/forum/#!topic/hg-git/uCua4hj1Jno . It’s currently not committed into the repository, but you can download and import the patch manually. There’s not really any documentation currently, but you can look at the example in `tests/test-export-additional-refs.t`. If you pull from Git back to Mercurial, you’ll end up with additional bookmarks. – Manuel Jacob Nov 21 '19 at 00:18
  • Yes only hg -> git. After trying varios tools (and their various versions) I actually ended up using github import tool which can handle theopen branches just fine with no extra work. The only thing it cannot handle are subrepositories, which should be exportable with `hg-fast-export`, but I haven't much luck with it so leaving those without joined history. – Jan Nov 21 '19 at 07:56

2 Answers2

6

Can hggit somehow pick all open branches

Yes. You miss option in hg-git

branch_bookmark_suffix = SOME-STRING

which translates (transparently) named branches of Mercurial in "branches" of Git (and backward, if needed). Sample from my personal config

[git]
branch_bookmark_suffix =_bkm

All HG-branches will get this _bkm suffix in Git-repo and will be known under this full name as Git-branches, but will return to "stripped" form after appearing in any HG-repo with the same settings as my

Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
  • thanks for a very helpful pointer. From doc https://bitbucket.org/durin42/hg-git/src/default/ it seems this is suppesed to be added to hgrc. I added it there, run the `hg bookmark -r default master`, then `hg push ` yet it still doesn't push the commits in open branches – Jan Nov 17 '19 at 11:19
  • If that works for you - can you please share your version of hg and hggit? I got some troubles to make those working together and most stable combination working for me was hg 4.5.2 and hggit 2018-02-24. I'm wondering if maybe the `branch_bookmark_suffix` is not ignored in that version – Jan Nov 17 '19 at 11:46
  • 1
    Ah - now I see that actually I need to first manually add the proper bookmarks.. I was hping the transform would do this on my behalf. Do you possibly know about any way how to automatically create those (I have dozens of repos to transform and each having dozens of branches). – Jan Nov 17 '19 at 20:38
  • @Jan - AFACR, no... you have only define suffix, which will be used for **all** named branches automagically. At least docs say it (I re-read it now). My hg-git is (from today's pull) `0.8.13+2` and `>hg --version Mercurial Distributed SCM (version 5.0.2)` – Lazy Badger Nov 18 '19 at 15:24
  • 1
    I’m confused by this answer. If I understand correctly, the `branch_bookmark_suffix` is completely unrelated to named branches. – Manuel Jacob Nov 21 '19 at 00:21
  • @ManuelJacob - sorry, but "no". Related, to named branches (which doesn't exist it *this*form in Git), in order to preserve branches and provide Hg-Git interoperability from Git-side as "additional storage" – Lazy Badger Nov 21 '19 at 00:38
3

It is worth noting that, whilst the hggit branch_bookmark_suffix will convert Mercurial bookmarks with that suffix into Git branches without that suffix, it does not explain that this does not apply to Mercurial named branches directly. Git branches are different from Mercurial branches, and are more akin to Mercurial bookmarks, except that they are shared in the repository, rather than just being local.

In order for hggit branch_bookmark_suffix to apply to Mercurial named branches, these need to have Mercurial bookmarks with the appropriate suffix to be converted to Git branches.

For example, in addition to adding hggit to the hgrc:

[extensions]
hgext.bookmarks =
hggit =

[git]
branch_bookmark_suffix = _bookmark

One also needs to add a Mercurial (local) bookmark for each named branch. For example, the following bash script can be used to do this - note this handles the Mercurial default branch separately, so that it corresponds to the Git master branch.

#!/bin/bash

BRANCHES=`hg branches`

for BRANCH in ${BRANCHES[@]}; do
    if [[ ! "$BRANCH" =~ ^([0-9]+:)|(inactive)|(closed) ]];
    then 
        echo $BRANCH
        if [[ "$BRANCH" =~ "default" ]];
        then 
            `hg bookmark -r "${BRANCH}" "master"`
        else
            `hg bookmark -r "${BRANCH}" "${BRANCH}_bookmark"`
        fi 
    fi
done
amaidment
  • 6,942
  • 5
  • 52
  • 88
  • @LazyBadger - I think you might need to read the manual, which states "if an hg repo had a named branch called release_6_maintenance, you could then link it to a bookmark called release_6_maintenance_bookmark. hg-git will then strip off the \_bookmark suffix from this bookmark name, and create a git branch called release_6_maintenance". This is what I am saying - that you need a hg _bookmark_ to be converted to a git _branch_. hggit does **not** convert the hg _branch_ to a git _branch_. – amaidment Jun 01 '20 at 15:47
  • Why the downvote? I'm addressing an omission in the accepted answer, and providing a helpful script that might assist others with the same problem. – amaidment Jun 02 '20 at 10:58