hggit doesn't export unmerged branches

693 Views Asked by At

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)?

2

There are 2 best solutions below

6
Lazy Badger On BEST ANSWER

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

2
amaidment On

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