[PATCH RESEND] forget: add --ignored option (issue2487)

Dan Villiom Podlaski Christiansen danchr at gmail.com
Mon Dec 27 03:08:20 CST 2010


# HG changeset patch
# User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
# Date 1293440883 -3600
# Node ID 1dbd1b2fdc53bdfac6be9f916e6366dafcf13f8a
# Parent  7f15cade251fc45db9a4b5fc5fc4e1b75f2fca4c
forget: add --ignored option (issue2487)

Rather than littering the implementation of 'forget' with
conditionals, a single if-statement is added and a bit of code
copy-pasted.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1579,6 +1579,27 @@ def forget(ui, repo, *pats, **opts):
     Returns 0 on success.
     """
 
+    if opts.pop('ignored'):
+        m = pats and cmdutil.match(repo, pats, opts) or cmdutil.matchall(repo)
+        s = repo.status(match=m, clean=True)
+        files = sorted(s[0] + s[1] + s[3] + s[6])
+        forget = []
+        errs = 0
+
+        for f in files:
+            if repo.dirstate._ignore(f):
+                if ui.verbose or not m.exact(f):
+                    ui.status(_('removing %s\n') % m.rel(f))
+                forget.append(f)
+            elif m.exact(f):
+                ui.warn(_('not removing %s: file would not be ignored\n')
+                        % m.rel(f))
+                errs = 1
+
+        repo[None].remove(forget, unlink=False)
+
+        return errs
+
     if not pats:
         raise util.Abort(_('no files specified'))
 
@@ -4223,7 +4244,9 @@ table = {
          _('[OPTION]... [-o OUTFILESPEC] REV...')),
     "^forget":
         (forget,
-         [] + walkopts,
+         [('i', 'ignored', None,
+           _('forget files that would otherwise have been ignored')),
+         ] + walkopts,
          _('[OPTION]... FILE...')),
     "grep":
         (grep,
diff --git a/tests/test-add.t b/tests/test-add.t
--- a/tests/test-add.t
+++ b/tests/test-add.t
@@ -97,3 +97,15 @@ Issue683: peculiarity with hg revert of 
   A c
   ? a.orig
 
+Test forgetting files that would otherwise have been ignored
+
+  $ cat > .hgignore <<EOF
+  > ^a$
+  > ^b$
+  > EOF
+  $ hg forget --ignored a
+  $ hg forget --ignored
+  removing b
+  $ hg forget --ignored c
+  not removing c: file would not be ignored
+  [1]
diff --git a/tests/test-debugcomplete.t b/tests/test-debugcomplete.t
--- a/tests/test-debugcomplete.t
+++ b/tests/test-debugcomplete.t
@@ -183,7 +183,7 @@ Show all commands + options
   commit: addremove, close-branch, include, exclude, message, logfile, date, user
   diff: rev, change, text, git, nodates, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, unified, stat, include, exclude, subrepos
   export: output, switch-parent, rev, text, git, nodates
-  forget: include, exclude
+  forget: ignored, include, exclude
   init: ssh, remotecmd
   log: follow, follow-first, date, copies, keyword, rev, removed, only-merges, user, only-branch, branch, prune, patch, git, limit, no-merges, stat, style, template, include, exclude
   merge: force, tool, rev, preview


More information about the Mercurial-devel mailing list