Mercurial error: repository is unrelated

后端 未结 4 1746
感动是毒
感动是毒 2021-01-01 09:09

I\'ve just started with Mercurial, I have a \'central\' repository on Bitbucket which I cloned onto one machine and made changes and committed and pushed. I then cloned from

4条回答
  •  鱼传尺愫
    2021-01-01 09:53

    I would like to share knowledge about Mercurial internals.

    Repositories unrelated when they have no any same revisions.

    Corresponding piece you can find in mercurial/treediscovery.py:

    base = list(base)
    if base == [nullid]:
        if force:
            repo.ui.warn(_("warning: repository is unrelated\n"))
        else:
            raise util.Abort(_("repository is unrelated"))
    

    base is a list of roots of common parts in both local/remote repositories.

    You always may know how repositories are different by:

    $ hg in $REMOTE
    $ hg out $REMOTE
    

    You always may checks roots of both (after cloning both locally):

    $ hg -R $ONE log -r "roots(all())"
    $ hg -R $TWO log -r "roots(all())"
    

    if output from above commands doesn't share IDs - those repositories are unrelated. Due to hash properties it is very impossible that roots be equal accidentally. You may not trick roots checking by carefully crafting repositories because building two repositories looks like these (with common parts but different roots):

    0 <--- SHA-256-XXX <--- SHA-256-YYY <--- SHA-256-ZZZ
    0 <--- SHA-256-YYY <--- SHA-256-ZZZ
    

    impossible because that mean you reverse SHA-256 as each subsequent hash depends on previous values.

    Having this info I believe any Devs be able to troubleshoot error: repository is unrelated.

    See also Mercurial repository identification

    Thanks for attention, good hacking!

提交回复
热议问题