Adding a Git subrepository to Mercurial

2019-03-14 19:49发布

I've been trying to set up a project using bitbucket which has project dependencies hosted on github. Using the Hg-Git Mercurial plugin I am able to almost get there.

But when it comes time to push, things become troublesome.

The documentation for Mercurial subrepositories states:

2.4 Push

Mercurial will automatically attempt to first push all subrepos of the current repository when you push. This will ensure new changesets in subrepos are available when referenced by top-level repositories.

But this causes a big issue since I don't want to push all the subrepositories (why would I?) — I only have read access to them, so github won't allow it. Only the main repository needs to be pushed to the remote server, but I can't figure out how to do it. hg wants to take control and push all subrepositories, regardless of whether or not there are changes. Is there some way to bypass this feature?

The only things which need to be pushed are .hgsub and .hgsubstate. Once they've been pushed via alternative routes (updating to a changeset where the subrepositories don't exist), it's possible to then update and pull the changes from the remote repositories, but if I were to push again whilst on a changeset with the subrepositories, the whole ordeal repeats itself.

4条回答
再贱就再见
2楼-- · 2019-03-14 20:07

For future reference, the development branch of mercurial (and thus the upcoming 1.8 release) now supports native git subrepos. This particular case is implemented very nicely and a push from the root repository will only tell the git subrepo to push if its remote repository is not known to have the current commit.

查看更多
地球回转人心会变
3楼-- · 2019-03-14 20:17

This isn't possible due to Mercurial's method of pushing. This is a by design error.

The best solution is to update to a previous revision where the subrepositories don't exist, and then push. This will bypass Mercurial's restriction and upload the necessary .hgsub and .hgsubstate files. This is a little inconvenient, but is the best way I've found so far to get Mercurial and Git to work with each other.

Perhaps in the future Hg-Git will be updated to handle this use case automatically.

查看更多
Evening l夕情丶
4楼-- · 2019-03-14 20:17

If you have no outgoing changesets in the subrepository, the 'push' should actually do nothing other than retrieve the latest changeset list from the remote repository. Therefore, the actual 'push' part of the push won't happen. I've successfully used read-only BitBucket repositories as submodules.

查看更多
再贱就再见
5楼-- · 2019-03-14 20:25

I think you should use multiple repositories; DVCS works better like that.

For example, make one repository that contains the dependencies from github. You only pull in that repo to get the changes, you never push. Then you have another repository for your project, for development. Here you are free to do whatever you want. And then you link to your own hg repo for the dependencies.

That's if I correctly understood your problem and what you're trying to do :)

查看更多
登录 后发表回答