diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -2381,8 +2381,19 @@ def add(ui, repo, match, prefix, uipathf full=False, ) ): + entry = dirstate.get_entry(f) + # We don't want to even attmpt to add back files that have been removed + # It would lead to a misleading message saying we're adding the path, + # and can also lead to file/dir conflicts when attempting to add it. + removed = entry and entry.removed exact = match.exact(f) - if exact or not explicitonly and f not in wctx and repo.wvfs.lexists(f): + if ( + exact + or not explicitonly + and f not in wctx + and repo.wvfs.lexists(f) + and not removed + ): if cca: cca(f) names.append(f) diff --git a/tests/test-symlinks.t b/tests/test-symlinks.t --- a/tests/test-symlinks.t +++ b/tests/test-symlinks.t @@ -210,14 +210,10 @@ can add with --include $ hg add -I foo adding foo - adding foo/a (known-bad-output !) - abort: file 'foo' in dirstate clashes with 'foo/a' (known-bad-output !) - [255] $ hg status A bar/a - A foo (missing-correct-output !) + A foo R foo/a - ? foo (known-bad-output !) $ cd ..