How to fix Mercurial stuck on Git subrepo push?
Asked Answered
D

1

8
  1. I have root Mercurial repo (web site).
  2. I clone WordPress from GitHub mirror into /wp subdirectory.
  3. Since I want very specific (stable) version of WP, but no ongoing development I do git checkout 3.4.1 (where 3.4.1 is tag).
  4. I setup it as subrepo in root Mercurial repo and commit (WP revision gets captured fine in .hgsubstate).

And here trouble starts. I do hg push and when it gets to WP:

no branch checked out in subrepo wp
cannot push revision e9bc63e25dc40c07ac3a6778dc2b48e1aa486e36

And then it just quits. Push for root repo is not even attempted.

I understand why Mercurial tries to push subrepo (intended behavior), but I can't make sense why it manages to fail completely on subrepo that:

  1. has no changes
  2. has read-only origin anyway

How to make it understand that I want this specific revision and I don't want it messing with Git subrepo?

Disputable answered 11/7, 2012 at 16:45 Comment(0)
S
4

You are going to run into a couple problems with this setup.

First, it seems that mercurial cannot handle git subrepos with a detached HEAD.

When you execute git checkout 3.4.1, your repo enters a detached HEAD state (you should have seen a warning to that effect when you executed the command). At that point, if you run git branch, you see that (no branch) is listed as the active branch. When mercurial attempts to push, it chokes on this state. You could ask the mercurial developer list why this happens, but it probably a limitation of the existing subrepo implementation.

Second, mercurial uses a push command to synchronize git subrepos.

If you were to run git checkout -b <integration_branch> 3.4.1, it moves git out of the detached HEAD state. However, when you try to hg push, it will attempt to actually push to the remote git repo. For a mercurial subrepo, it can check for outgoing changes even if you don't have push access to the remote. However, GitHub requires you to authenticate before it will tell you if the two repos are synchronized. So, if you don't have push access to the git remote then this will fail. This is part of the design of mercurial's subrepo strategy.

If you need to continue with this setup, you should probably do the following:

  1. Create your own fork of the WordPress repo on GitHub.
  2. Clone your fork into the mercurial subrepo directory.
  3. git checkout -b <branch_name> 3.4.1
  4. Continue from there

There is some additional info in this related question.

Seamanlike answered 13/7, 2012 at 15:2 Comment(2)
Yep, it seems detached head is the issue here (although I see it as Git shortcoming not Mercurial - if it doesn't have anything to push what the heck active branch matter?..). Your second point seems to be non-issue however, other GitHub subrepos updated to tip revision work fine. My current solution is to create and use Mercurial mirror of WordPress, but still interested if this detached stuff can be made work as subrepo without cloning and branching things around...Disputable
@Rarst: as long as your other GitHub subrepos point to tip, it will be fine. But as soon as you create a local git branch to use an earlier revision (e.g. use an older tag, without a detached HEAD), you will get the same error.Seamanlike

© 2022 - 2024 — McMap. All rights reserved.