Commit fe342d0c authored by Anton Shestakov's avatar Anton Shestakov
Browse files

topic: don't lose any file changes when changing topic of a merge commit

This file-related logic is taken directly from cmdutil.amend().

--HG--
branch : stable
parent 13c406d9912c
Pipeline #22081 passed with stage
in 5 minutes and 2 seconds
......@@ -6,6 +6,10 @@ Changelog
* next: remove duplicated targets when updating from an unstable changeset
topic (0.22.2)
* topic: don't lose any file changes when changing topic of a merge commit
10.3.1 -- 2021-04-25
--------------------
......
......@@ -1059,6 +1059,14 @@ def _changetopics(ui, repo, revs, newtopic):
for r in revs:
c = repo[r]
if len(c.parents()) > 1:
# ctx.files() isn't reliable for merges, so fall back to the
# slower repo.status() method
st = c.p1().status(c)
files = set(st.modified) | set(st.added) | set(st.removed)
else:
files = set(c.files())
def filectxfn(repo, ctx, path):
try:
return c[path]
......@@ -1097,7 +1105,7 @@ def _changetopics(ui, repo, revs, newtopic):
mc = context.memctx(repo,
(p1, p2),
c.description(),
c.files(),
files,
filectxfn,
user=c.user(),
date=c.date(),
......
......@@ -70,3 +70,29 @@ metaedit
+++ b/apple Thu Jan 01 00:00:00 1970 +0000
@@ -0,0 +1,1 @@
+apple
topics
$ hg topics -r . foo
switching to topic foo
changed topic on 1 changesets to "foo"
$ hg diff -r 'p1(.)' -r '.'
diff -r 88a060ab6523 -r 52150b9639f7 banana
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/banana Thu Jan 01 00:00:00 1970 +0000
@@ -0,0 +1,1 @@
+banana
$ hg diff -r 'p2(.)' -r '.'
diff -r d8c7baf0ca58 -r 52150b9639f7 apple
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/apple Thu Jan 01 00:00:00 1970 +0000
@@ -0,0 +1,1 @@
+apple
$ hg files
apple
banana
root
$ hg cat apple banana
apple
banana
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment