diff --git a/mercurial/merge.py b/mercurial/merge.py --- a/mercurial/merge.py +++ b/mercurial/merge.py @@ -1887,11 +1887,14 @@ ) wantfiledata = updatedirstate and not branchmerge - copies = {} + resulting_copies = {} # We don't want to record copies when doing `hg update -C` (which is # what `overwrite` is about) if not overwrite: - copies = _extract_copies(actions, branchmerge) + existing_copies = wc.p2copies() + existing_copies.update(wc.p1copies()) + new_copies = _extract_copies(actions, branchmerge) + resulting_copies = copies.chain(existing_copies, new_copies) stats, getfiledata = applyupdates( repo, actions, wc, p2, overwrite, wantfiledata, labels=labels @@ -1910,7 +1913,14 @@ if not branchmerge: repo.dirstate.setbranch(p2.branch()) - for dst, src in copies.items(): + # This replicates copies.filter() but is modified to work with merges + for dst, src in resulting_copies.items(): + if dst == src: + continue + if dst not in wc: + continue + if not (src in wc.p1() or src in wc.p2()): + continue wc[dst].markcopied(src) # If we're updating to a location, clean up any stale temporary includes