How to clone topics in mercurial?

111 Views Asked by At

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
2

There are 2 best solutions below

0
On BEST ANSWER

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

# source_repo/.hg/hgrc

[phases]
publish = false
1
On

Consider this a workaround, perhaps, but it should work.

If you're just working locally, you don't actually have to clone. You could just make a full copy of the entire working folder (the folder which contains the .hg folder).

Copy it anywhere you want, then when you run Mercurial commands within that path it will behave exactly like it was cloned, except it won't see your original as the default publishing repo, but instead the same one as your original. You can obviously change this in the .hgrc file if you need to.

Depending on your needs, you might want to do an hg up null beforehand to clear all the local working files, which will speed up the copy for a large repo.