开发者

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

开发者 https://www.devze.com 2023-04-10 10:40 出处:网络
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 loc开发者_如何学运维ation of B, but it\'s

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 loc开发者_如何学运维ation 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?


$ 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.


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


It could be easier to tamper with DNS as a quick workaround (e.g. hosts file on Windows) and then fix .hgsub.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号