--- a/mercurial/cmdutil.py Wed Nov 22 22:18:06 2017 +0800
+++ b/mercurial/cmdutil.py Thu Nov 30 15:48:42 2017 -0500
@@ -3166,6 +3166,18 @@
raise error.Abort(
_("failed to mark all new/missing files as added/removed"))
+ # Check subrepos. This depends on in-place wctx._status update in
+ # subrepo.precommit(). To minimize the risk of this hack, we do
+ # nothing if .hgsub does not exist.
+ if '.hgsub' in wctx or '.hgsub' in old:
+ from . import subrepo # avoid cycle: cmdutil -> subrepo -> cmdutil
+ subs, commitsubs, newsubstate = subrepo.precommit(
+ ui, wctx, wctx._status, matcher)
+ # amend should abort if commitsubrepos is enabled
+ assert not commitsubs
+ if subs:
+ subrepo.writestate(repo, newsubstate)
+
filestoamend = set(f for f in wctx.files() if matcher(f))
changes = (len(filestoamend) > 0)
@@ -3179,9 +3191,11 @@
# introduced file X and the file was renamed in the working
# copy, then those two files are the same and
# we can discard X from our list of files. Likewise if X
- # was deleted, it's no longer relevant
+ # was removed, it's no longer relevant. If X is missing (aka
+ # deleted), old X must be preserved.
files.update(filestoamend)
- files = [f for f in files if not samefile(f, wctx, base)]
+ files = [f for f in files if (not samefile(f, wctx, base)
+ or f in wctx.deleted())]
def filectxfn(repo, ctx_, path):
try:
@@ -3193,12 +3207,11 @@
if path not in filestoamend:
return old.filectx(path)
+ # Return None for removed files.
+ if path in wctx.removed():
+ return None
+
fctx = wctx[path]
-
- # Return None for removed files.
- if not fctx.exists():
- return None
-
flags = fctx.flags()
mctx = context.memfilectx(repo,
fctx.path(), fctx.data(),