diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -536,7 +536,8 @@
         if not self.in_merge:
             msg = _(b"setting %r to other parent only allowed in merges") % f
             raise error.Abort(msg)
-        if f in self and self[f] == b'n':
+        entry = self._map.get(f)
+        if entry is not None and entry.tracked:
             # merge-like
             self._addpath(f, merged=True)
         else: