Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with Git submodules on a repo that is converted to Mercurial

Here goes:

$ cat .gitmodules 
[submodule "utils/external/firepython"]
    path = utils/external/firepython
    url = git://github.com/darwin/firepython.git
[submodule "utils/external/textile"]
    path = utils/external/textile
    url = git://github.com/jsamsa/python-textile.git

While this was still a Git repo, I needed to run git submodule init, after which some magic happens. Since I've now converted the repo to Mercurial (using hgext.git extension), I don't know what to do. Is there an equivalent process (I need those 2 Git modules in my Mercurial repo)?

like image 273
tshepang Avatar asked Apr 10 '11 14:04

tshepang


People also ask

How do I manage git submodules?

Use the git submodule update command to set the submodules to the commit specified by the main repository. This means that if you pull in new changes into the submodules, you need to create a new commit in your main repository in order to track the updates of the nested submodules.

Which command will you use to update all submodules in your repository?

If you pass --recurse-submodules to the git clone command, it will automatically initialize and update each submodule in the repository, including nested submodules if any of the submodules in the repository have submodules themselves.

Does git clone pull submodules?

It automatically pulls in the submodule data assuming you have already added the submodules to the parent project. Note that --recurse-submodules and --recursive are equivalent aliases.

When should I use git submodules?

In most cases, Git submodules are used when your project becomes more complex, and while your project depends on the main Git repository, you might want to keep their change history separate. Using the above as an example, the Room repository depends on the House repository, but they operate separately.


1 Answers

Mercurial supports subrepositories of different kinds: Mercurial, Subversion, and Git. So you can create a .hgsub file with

utils/external/firepython = [git]git://github.com/darwin/firepython.git
utils/external/textile    = [git]git://github.com/jsamsa/python-textile.git

and that will inform Mercurial to make a clone of your Git repositories when the Mercurial repository is cloned. You need to make the Git clones yourself the first time, or copy them from somewhere else on your disk:

$ git clone git://github.com/darwin/firepython.git utils/external/firepython
$ git clone git://github.com/jsamsa/python-textile.git utils/external/textile
$ hg add .hgsub
$ hg commit -m 'Added Git subrepositories'

You will then note that Mercurial has added a .hgsubstate file to your repository where it stores information about the Git subrepositories. This file is needed so that Mercurial knows which revision to checkout from your subrepositories when you make a new Mercurial clone.

A colleague of mine has written a subrepository guide that you might find useful.

like image 79
Martin Geisler Avatar answered Oct 20 '22 20:10

Martin Geisler