changeset 17848:66f0c78350ab stable

remove: don't return error on directories with tracked files Spotted by Sergey <sergemp@mail.ru>
author Matt Mackall <mpm@selenic.com>
date Mon, 22 Oct 2012 16:06:47 -0500
parents 1e4eb1faba6e
children 6da47b655d97
files mercurial/commands.py tests/test-remove.t
diffstat 2 files changed, 24 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Sat Oct 20 21:43:46 2012 -0400
+++ b/mercurial/commands.py	Mon Oct 22 16:06:47 2012 -0500
@@ -4842,11 +4842,18 @@
     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
--- a/tests/test-remove.t	Sat Oct 20 21:43:46 2012 -0400
+++ b/tests/test-remove.t	Mon Oct 22 16:06:47 2012 -0500
@@ -265,4 +265,17 @@
   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]