Adding a Git subrepository to Mercurial
Asked Answered
F

4

17

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.

Fornicate answered 30/10, 2010 at 8:27 Comment(0)
F
4

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.

Fornicate answered 31/10, 2010 at 17:51 Comment(1)
it is an error that manifestates when using github, hg-git and a subrepository feature, try to use native git subrepositoryApps
S
12

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.

Sarcocarp answered 30/11, 2010 at 16:11 Comment(1)
Here is some detail for native support of git subrepo's inside mecurial mercurial.selenic.com/wiki/Subrepository#Git_subrepositoriesTorrential
F
4

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.

Fornicate answered 31/10, 2010 at 17:51 Comment(1)
it is an error that manifestates when using github, hg-git and a subrepository feature, try to use native git subrepositoryApps
N
2

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

Nicker answered 30/10, 2010 at 20:28 Comment(2)
Sorry, I don't understand. My problem is that I need Mercurial and Git to play nicely with eachother — which they do. But hg's so-called feature just makes things a little troublesome.Fornicate
It is not a "so-called feature", it's an essential step in working with hg. Push/pull synchronizes your local repository with the remote one. What I am suggesting is that you might need a different repository configuration for what you are trying to do; it's common when using git/mercurial to have multiple repositories for your project. Pushing in your mercurial repo shouldn't affect the stuff you are trying to get from github and of course you shouldn't be pushing into the github repo.Nicker
R
0

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.

Rationality answered 30/10, 2010 at 13:35 Comment(1)
Yes it should, which is exactly what it does — however the push does actually happen, it's just that if there are no changes then nothing will be uploaded. Github forces you to authenticate yourself before checking to see if there are any changes. So for this to work, the push needs to be ignored completely.Fornicate

© 2022 - 2024 — McMap. All rights reserved.