Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloning a mercurial repository, .hgsub refers to a dead external subrepo

Tags:

mercurial

We're trying to clone a Mercurial repository A where it references a subrepository B that's moved hosts. We'd like to update .hgsub in A to point to the new location of B, but it's a chicken and egg problem if we can't hg clone A in the first place.

Does anyone know how to work around this?

like image 805
Mark Wang Avatar asked Sep 30 '11 23:09

Mark Wang


People also ask

How do I clone a Mercurial repository?

Clone a remote Mercurial repositoryFrom the main menu, select Hg | Get from Version Control. The Get from Version Control dialog opens. In the dialog that opens, select Mercurial from the Version control list and specify the URL of the remote repository you want to clone. Click Clone.

What is a Subrepo?

Subrepositories is a feature that allows you to treat a collection of repositories as a group. This will allow you to clone, commit to, push, and pull projects and their associated libraries as a group. This feature was introduced in a preliminary form in Mercurial 1.3 and has been improved steadily since then.


2 Answers

$ hg help subrepos
...

    Remapping Subrepositories Sources
    ---------------------------------

    A subrepository source location may change during a project life,
    invalidating references stored in the parent repository history. To fix
    this, rewriting rules can be defined in parent repository "hgrc" file or
    in Mercurial configuration. See the "[subpaths]" section in hgrc(5) for
    more details.

$ man hgrc
...

   subpaths
       Defines subrepositories source locations rewriting rules of the form:

       <pattern> = <replacement>

       Where  pattern  is  a regular expression matching the source and replacement is the replacement string used to
       rewrite it. Groups can be matched in pattern and referenced in replacements. For instance:

       http://server/(.*)-hg/ = http://hg.server/\1/

       rewrites http://server/foo-hg/ into http://hg.server/foo/.

       All patterns are applied in definition order.

...

So, you can do it in .hgrc in a [subpaths] section.

like image 113
Chris Morgan Avatar answered Sep 24 '22 08:09

Chris Morgan


First note that clone is init + pull + update and that subrepo cloning is part of the update step, not the pull step. This means that you can avoid clone failing simply by skipping the update step:

$ hg clone -U <url>

Now the problem is reduced to "how do I update to a revision with a problematic .hgsub/.hgsubstate file?" There are two possibilities here:

  • remap subrepos using the [subpaths] feature (see hg help subrepo and hg help config)

  • manual update and repair

A "manual update" can be done like this:

$ hg revert -a -r default -X problematic-file
[adding a bunch of files]
$ hg debugrebuildstate -r default

Now you can manually fix-up your subrepos and .hgsub and commit. Be sure to test your fix with a clone before pushing it.

Also, see this mailing list thread on the topic: http://markmail.org/thread/ktxd2rsm7avkexzr

like image 30
mpm Avatar answered Sep 23 '22 08:09

mpm