Fix up remove command to use walk code.
authorBryan O'Sullivan <bos@serpentine.com>
Thu, 01 Sep 2005 07:48:14 -0700
changeset 1188 b3ceb2d470fc
parent 1187 120aa5fc7ced
child 1189 4cbcc54695b2
Fix up remove command to use walk code.
doc/hg.1.txt
mercurial/commands.py
--- a/doc/hg.1.txt	Thu Sep 01 07:47:26 2005 -0700
+++ b/doc/hg.1.txt	Thu Sep 01 07:48:14 2005 -0700
@@ -403,7 +403,7 @@
     This command tries to fix the repository status after an interrupted
     operation. It should only be necessary when Mercurial suggests it.
 
-remove [files ...]::
+remove [options] [files ...]::
     Schedule the indicated files for removal from the repository.
     
     This command schedules the files to be removed at the next commit.
--- a/mercurial/commands.py	Thu Sep 01 07:47:26 2005 -0700
+++ b/mercurial/commands.py	Thu Sep 01 07:48:14 2005 -0700
@@ -1262,9 +1262,23 @@
     """roll back an interrupted transaction"""
     repo.recover()
 
-def remove(ui, repo, file1, *files):
+def remove(ui, repo, pat, *pats, **opts):
     """remove the specified files on the next commit"""
-    repo.remove(relpath(repo, (file1,) + files))
+    names = []
+    for src, abs, rel, exact in walk(repo, (pat,) + pats, opts):
+        if exact:
+            skip = {'m': 'file has pending merge',
+                    'a': 'file has been marked for add (use forget)',
+                    '?': 'file not managed'}
+            reason = skip.get(repo.dirstate.state(abs))
+            if reason:
+                ui.warn('not removing %s: %s\n' % (rel, reason))
+            else:
+                names.append(abs)
+        elif repo.dirstate.state(abs) == 'n':
+            ui.status('removing %s\n' % rel)
+            names.append(abs)
+    repo.remove(names)
 
 def revert(ui, repo, *names, **opts):
     """revert modified files or dirs back to their unmodified states"""
@@ -1697,7 +1711,10 @@
           ('l', 'logfile', "", 'commit message file')],
          'hg rawcommit [OPTION]... [FILE]...'),
     "recover": (recover, [], "hg recover"),
-    "^remove|rm": (remove, [], "hg remove FILE..."),
+    "^remove|rm": (remove,
+                   [('I', 'include', [], 'include path in search'),
+                    ('X', 'exclude', [], 'exclude path from search')],
+                   "hg remove [OPTION]... FILE..."),
     "^revert":
         (revert,
          [("n", "nonrecursive", None, "don't recurse into subdirs"),