Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to use a Mercurial repository as Git submodule?

I been happily using submodules to track all the libraries my project depends from. The thing is I'm using a library called core-plot that only has a public mercurial repository. I can probably mirror it in a readonly Git repository, but is this the best option I got? I had seen there is modules in Mercurial to track things in Git. Someone know if the other way around exists?

like image 941
dvicino Avatar asked Jan 30 '12 16:01

dvicino


People also ask

How do I create a submodule from an existing repo?

In order to add a Git submodule, use the “git submodule add” command and specify the URL of the Git remote repository to be included as a submodule. When adding a Git submodule, your submodule will be staged. As a consequence, you will need to commit your submodule by using the “git commit” command.

Why you should not use Git submodules?

This is because of some major drawbacks around git submodules, such as being locked to a specific version of the outer repo, the lacking of effective merge management, and the general notion that the Git repository itself doesn't really know it's now a multi-module repository.


2 Answers

Using git-hg.

First, make sure there is a (non-Mercurial) git submodule under your main repository. If you don't have other submodules yet, just create a dummy submodule for some library other than core-plot, for instance:

main-repo $ git submodule add https://repo.url.com/repo.git repo 

Second, clone the core-plot library into some directory.

main-repo $ git-hg clone  https://code.google.com/p/core-plot/ core-plot 

Add the new repo to the submodule list.

main-repo $ git submodule add ./core-plot core-plot main-repo $ git commit -am "added core-plot submodule" 

From now on, any clone from this repo will pull both repositories. (After submodule init and update).

Some problems I found out so far are:

  • If you push to a bare, then the repo link and the directory will be created in the bare, but the repository will not be cloned inside it and others pulling from that bare will not be able to get the core-plot lib.
  • If core-plot needs to be updated the one with the git-hg will have to git-hg pull.

The converse question git submodule from Hg repo? is also asked on StackOverflow. The best answer mentions projects hg-git and git-hg. Another related converse question is, How to deal with Git submodules on a repo that is converted to Mercurial.

like image 61
Jim DeLaHunt Avatar answered Sep 24 '22 23:09

Jim DeLaHunt


In my experience, most active non-git projects have an up-to-date git mirror floating around on GitHub. It looks like core-plot has one too:

https://github.com/djw/core-plot

If you're willing to rely on whoever set that mirror up, it seems like it might be the easiest option to get a submodule in place.

like image 25
phinze Avatar answered Sep 22 '22 23:09

phinze