diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -2531,12 +2531,16 @@ def revert(ui, repo, ctx, parents, *pats dsmodified = modified dsadded = added dsremoved = removed + # store all local modifications, useful later for rename detection + localchanges = dsmodified | dsadded modified, added, removed = set(), set(), set() else: changes = repo.status(node1=parent, match=m) dsmodified = set(changes[0]) dsadded = set(changes[1]) dsremoved = set(changes[2]) + # store all local modifications, useful later for rename detection + localchanges = dsmodified | dsadded # only take into account for removes between wc and target clean |= dsremoved - removed @@ -2570,7 +2574,7 @@ def revert(ui, repo, ctx, parents, *pats # if f is a rename, update `names` to also revert the source cwd = repo.getcwd() - for f in dsadded: + for f in localchanges: src = repo.dirstate.copied(f) # XXX should we check for rename down to target node? if src and src not in names and repo.dirstate[src] == 'r': diff --git a/tests/test-revert.t b/tests/test-revert.t --- a/tests/test-revert.t +++ b/tests/test-revert.t @@ -234,6 +234,12 @@ reverting a rename target should revert $ hg st a newa ? newa +Also true for move overwriting an existing file + + $ hg mv --force a b/b + $ hg revert b/b + $ hg status a b/b + $ cd .. $ hg init ignored