[PATCH 5 of 5 V2] debugignore: find out why a file is being ignored (issue4856)

Augie Fackler raf at durin42.com
Thu Dec 31 10:41:20 CST 2015


On Sat, Dec 26, 2015 at 07:41:34PM -0800, Laurent Charignon wrote:
> # HG changeset patch
> # User Laurent Charignon <lcharignon at fb.com>
> # Date 1451187668 28800
> #      Sat Dec 26 19:41:08 2015 -0800
> # Node ID 98bc6f7cfe017d742b580eda73f665e2466b972b
> # Parent  6c9520b882569ba16cb02745ab3bd9bb8f1dadfb
> debugignore: find out why a file is being ignored (issue4856)

Queued these, very nice.

>
> This patch adds a capability to hg debugignore: to explain why a given file is
> being ignores by mercurial. We display the filename, line and linenumber of the
> rule that lead us to ignore the file.
>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -2438,7 +2438,8 @@
>
>      With no argument display the combined ignore pattern.
>
> -    Given space separated file names, shows if the given file is ignored.
> +    Given space separated file names, shows if the given file is ignored and
> +    if so, show the ignore rule (file and line number) that matched it.
>      """
>      ignore = repo.dirstate._ignore
>      if not files:
> @@ -2451,13 +2452,16 @@
>      else:
>          for f in files:
>              ignored = None
> +            ignoredata = None
>              if f != '.':
>                  if ignore(f):
>                      ignored = f
> +                    ignoredata = repo.dirstate._ignorefileandline(f)
>                  else:
>                      for p in util.finddirs(f):
>                          if ignore(p):
>                              ignored = p
> +                            ignoredata = repo.dirstate._ignorefileandline(p)
>                              break
>              if ignored:
>                  if ignored == f:
> @@ -2465,6 +2469,9 @@
>                  else:
>                      ui.write("%s is ignored because of containing folder %s\n"
>                               % (f, ignored))
> +                ignorefile, lineno, line = ignoredata
> +                ui.write("(ignore rule in %s, line %d: '%s')\n"
> +                         % (ignorefile, lineno, line))
>              else:
>                  ui.write("%s is not ignored\n" % f)
>
> diff --git a/tests/test-hgignore.t b/tests/test-hgignore.t
> --- a/tests/test-hgignore.t
> +++ b/tests/test-hgignore.t
> @@ -168,6 +168,7 @@
>
>    $ hg debugignore b.o
>    b.o is ignored
> +  (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: '*')
>
>    $ cd ..
>
> @@ -198,6 +199,7 @@
>    a.c is not ignored
>    $ hg debugignore dir/c.o
>    dir/c.o is ignored
> +  (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 2: 'dir/**/c.o')
>
>  Check using 'include:' in ignore file
>
> @@ -283,3 +285,4 @@
>    [1]
>    $ hg debugignore dir1/file2
>    dir1/file2 is ignored
> +  (ignore rule in dir2/.hgignore, line 1: 'file*2')
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list