Patchwork [4,of,5,V2] debugignore: find out if a file is being ignored

login
register
mail settings
Submitter Laurent Charignon
Date Dec. 27, 2015, 3:41 a.m.
Message ID <6c9520b882569ba16cb0.1451187693@dev5073.prn1.facebook.com>
Download mbox | patch
Permalink /patch/12359/
State Superseded
Commit 067d87feeb11c11fb3ca1ee40b5fa242c93850ea
Headers show

Comments

Laurent Charignon - Dec. 27, 2015, 3:41 a.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@fb.com>
# Date 1450902887 28800
#      Wed Dec 23 12:34:47 2015 -0800
# Node ID 6c9520b882569ba16cb02745ab3bd9bb8f1dadfb
# Parent  674616200041c2bfd72cd93ea4dc4083804db6b6
debugignore: find out if a file is being ignored

Before this patch debugignore was just displaying the list of ignore patterns.
This patch makes it support a list of filename as argument and tells the user
if those given files are ignored or not.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2432,15 +2432,41 @@ 
         raise error.Abort(_('unknown bundle type specified with --type'))
     changegroup.writebundle(ui, bundle, bundlepath, bundletype)
 
-@command('debugignore', [], '')
-def debugignore(ui, repo, *values, **opts):
-    """display the combined ignore pattern"""
+@command('debugignore', [], '[FILE]')
+def debugignore(ui, repo, *files, **opts):
+    """display the combined ignore pattern and information about ignored files
+
+    With no argument display the combined ignore pattern.
+
+    Given space separated file names, shows if the given file is ignored.
+    """
     ignore = repo.dirstate._ignore
-    includepat = getattr(ignore, 'includepat', None)
-    if includepat is not None:
-        ui.write("%s\n" % includepat)
+    if not files:
+        # Show all the patterns
+        includepat = getattr(ignore, 'includepat', None)
+        if includepat is not None:
+            ui.write("%s\n" % includepat)
+        else:
+            raise error.Abort(_("no ignore patterns found"))
     else:
-        raise error.Abort(_("no ignore patterns found"))
+        for f in files:
+            ignored = None
+            if f != '.':
+                if ignore(f):
+                    ignored = f
+                else:
+                    for p in util.finddirs(f):
+                        if ignore(p):
+                            ignored = p
+                            break
+            if ignored:
+                if ignored == f:
+                    ui.write("%s is ignored\n" % f)
+                else:
+                    ui.write("%s is ignored because of containing folder %s\n"
+                             % (f, ignored))
+            else:
+                ui.write("%s is not ignored\n" % f)
 
 @command('debugindex', debugrevlogopts +
     [('f', 'format', 0, _('revlog format'), _('FORMAT'))],
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -829,7 +829,8 @@ 
    debugfsinfo   show information detected about current filesystem
    debuggetbundle
                  retrieves a bundle from a repo
-   debugignore   display the combined ignore pattern
+   debugignore   display the combined ignore pattern and information about
+                 ignored files
    debugindex    dump the contents of an index file
    debugindexdot
                  dump an index DAG as a graphviz dot file
diff --git a/tests/test-hgignore.t b/tests/test-hgignore.t
--- a/tests/test-hgignore.t
+++ b/tests/test-hgignore.t
@@ -166,6 +166,9 @@ 
   $ hg debugignore
   (?:(?:|.*/)[^/]*(?:/|$))
 
+  $ hg debugignore b.o
+  b.o is ignored
+
   $ cd ..
 
 Check patterns that match only the directory
@@ -191,6 +194,10 @@ 
   ? a.c
   ? a.o
   ? syntax
+  $ hg debugignore a.c
+  a.c is not ignored
+  $ hg debugignore dir/c.o
+  dir/c.o is ignored
 
 Check using 'include:' in ignore file
 
@@ -274,3 +281,5 @@ 
 
   $ hg status | grep file2
   [1]
+  $ hg debugignore dir1/file2
+  dir1/file2 is ignored