Wednesday, December 16, 2015

Converting hg repository to git

(offtopic for openstack, but important task for devops around CI).

Our CI wants git to build proper debian packages. We do not use mercurial in any way and all our internals are in gits. But external software we using is published in mercurial and do not provide pre-build packages.

We have decided to convert external hg to local git, and then proceed as usual.

Here the simple way to convert hg repository to git:
1) Install mercurial and hg-fast-export:
    sudo apt-get install -y mercurial hg-fast-export
2)  Clone hg repository to some temporal place: (e.g. /tmp):
    hg clone https://bitbucket.org/some/repo
3) Create new git repository in your gitlab/github
4) Create local empty git repository:
    mkdir ~/git/some_repo
    cd ~/git/some_repo
    git init
5) Run hg-fast-export:
    cd ~/git/some_repo
    hg-fast-export -r /tmp/some/repo
6) Add remote origin to git:
    git remote add origin git@internal_git:some_repo.git
7) Push changes:
    git push --all
8) Push tags:
    git push --tags

Thats all. No more strange thoughts about 'How to force intercourse between debian-jenkins-glue & mercurial'.

No comments:

Post a Comment