mercurialmercurial-phasesmercurial-topics

How to clone topics in mercurial?


Background: Mercurial Topics

Mercurial has a nice feature call topics as part of the evolve extension. These act as temporary lightweight local branches, and are an integral part of the Heptapod workflow, ensuring nice interactions with Git (via hg-git) for example. They are enabled by include the following in your ~/.hgrc file (or per-repo in .hg/hgrc):

# ~/.hgrc
...

[extensions]
evolve =
topics =

As these are designed for local work, when you push, the topics are not pushed to the server (but become temporary branches in git with the Heptapod workflow).

Question

How can I clone a repo locally to get the topics in my clone?

Part of the answer is to set the source repo to non-publishing: (One should probably do this in the cloned repo to after cloning).

# source_repo/.hg/hgrc

[phases]
publish = false

This keeps the draft phase of the changesets that are part of the topics.

Update: With python==3.9.7, mercurial==6.0.1, and hg-evolve==10.4.1 or higher, this seems to be sufficient. As @Craig points out in the comments, the original issue might have been because I was making the first commit a topic, but this is no longer an issue.

MWE (Old... This seems to work now.)

mkdir a
cd a
touch A.txt
hg init
hg add A.txt
hg topic "A"
hg commit -m "Initial commit of A"
cat > .hg/hgrc <<EOF
[phases]
publish = false
EOF
cd ..
hg clone a b

Now in a, there is a topic A and the commit is in the draft phase (shown by orange colour in the output):

$ hg log -v
changeset:   0:62c4...    # orange, indicating draft phase
tag:         tip
topic:       A
user:        Michael <...>
date:        Wed ...
files:       A.txt
description:
Initial commit of A

while in b, everything is the same, including the draft phase, but no topic:

$ hg log -v
changeset:   0:62c4...    # orange, indicating draft phase
tag:         tip
user:        Michael <...>
date:        Wed ...
files:       A.txt
description:
Initial commit of A

Solution

  • It seems like this was a localized bug. Making the source repo publishing seems to be enough.

    # source_repo/.hg/hgrc
    
    [phases]
    publish = false