# HG changeset patch # User Matt Mackall # Date 2012-10-22 21:06:47 # Node ID 66f0c78350abc19d6a4eb3574b5a4ea601dfb45c # Parent 1e4eb1faba6e6a68c14dc6ab07db858cdb0434d8 remove: don't return error on directories with tracked files Spotted by Sergey diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -4842,11 +4842,18 @@ def remove(ui, repo, *pats, **opts): s = repo.status(match=m, clean=True) modified, added, deleted, clean = s[0], s[1], s[3], s[6] + # warn about failure to delete explicit files/dirs + wctx = repo[None] for f in m.files(): - if f not in repo.dirstate and not os.path.isdir(m.rel(f)): - if os.path.exists(m.rel(f)): + if f in repo.dirstate or f in wctx.dirs(): + continue + if os.path.exists(m.rel(f)): + if os.path.isdir(m.rel(f)): + ui.warn(_('not removing %s: no tracked files\n') % m.rel(f)) + else: ui.warn(_('not removing %s: file is untracked\n') % m.rel(f)) - ret = 1 + # missing files will generate a warning elsewhere + ret = 1 if force: list = modified + deleted + clean + added diff --git a/tests/test-remove.t b/tests/test-remove.t --- a/tests/test-remove.t +++ b/tests/test-remove.t @@ -265,4 +265,17 @@ test that commit does not crash if the u nothing changed [1] - $ cd .. +handling of untracked directories and missing files + + $ mkdir d1 + $ echo a > d1/a + $ hg rm --after d1 + not removing d1: no tracked files + [1] + $ hg add d1/a + $ rm d1/a + $ hg rm --after d1 + removing d1/a + $ hg rm --after nosuch + nosuch: No such file or directory + [1]