Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 27672:f2da9bb87ae0
debugignore: find out why a file is being ignored (issue4856)
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.
author | Laurent Charignon <lcharignon@fb.com> |
---|---|
date | Tue, 05 Jan 2016 07:47:08 -0800 |
parents | 067d87feeb11 |
children | 60268a5f731a |
comparison
equal
deleted
inserted
replaced
27671:067d87feeb11 | 27672:f2da9bb87ae0 |
---|---|
2439 def debugignore(ui, repo, *files, **opts): | 2439 def debugignore(ui, repo, *files, **opts): |
2440 """display the combined ignore pattern and information about ignored files | 2440 """display the combined ignore pattern and information about ignored files |
2441 | 2441 |
2442 With no argument display the combined ignore pattern. | 2442 With no argument display the combined ignore pattern. |
2443 | 2443 |
2444 Given space separated file names, shows if the given file is ignored. | 2444 Given space separated file names, shows if the given file is ignored and |
2445 if so, show the ignore rule (file and line number) that matched it. | |
2445 """ | 2446 """ |
2446 ignore = repo.dirstate._ignore | 2447 ignore = repo.dirstate._ignore |
2447 if not files: | 2448 if not files: |
2448 # Show all the patterns | 2449 # Show all the patterns |
2449 includepat = getattr(ignore, 'includepat', None) | 2450 includepat = getattr(ignore, 'includepat', None) |
2452 else: | 2453 else: |
2453 raise error.Abort(_("no ignore patterns found")) | 2454 raise error.Abort(_("no ignore patterns found")) |
2454 else: | 2455 else: |
2455 for f in files: | 2456 for f in files: |
2456 ignored = None | 2457 ignored = None |
2458 ignoredata = None | |
2457 if f != '.': | 2459 if f != '.': |
2458 if ignore(f): | 2460 if ignore(f): |
2459 ignored = f | 2461 ignored = f |
2462 ignoredata = repo.dirstate._ignorefileandline(f) | |
2460 else: | 2463 else: |
2461 for p in util.finddirs(f): | 2464 for p in util.finddirs(f): |
2462 if ignore(p): | 2465 if ignore(p): |
2463 ignored = p | 2466 ignored = p |
2467 ignoredata = repo.dirstate._ignorefileandline(p) | |
2464 break | 2468 break |
2465 if ignored: | 2469 if ignored: |
2466 if ignored == f: | 2470 if ignored == f: |
2467 ui.write("%s is ignored\n" % f) | 2471 ui.write("%s is ignored\n" % f) |
2468 else: | 2472 else: |
2469 ui.write("%s is ignored because of containing folder %s\n" | 2473 ui.write("%s is ignored because of containing folder %s\n" |
2470 % (f, ignored)) | 2474 % (f, ignored)) |
2475 ignorefile, lineno, line = ignoredata | |
2476 ui.write("(ignore rule in %s, line %d: '%s')\n" | |
2477 % (ignorefile, lineno, line)) | |
2471 else: | 2478 else: |
2472 ui.write("%s is not ignored\n" % f) | 2479 ui.write("%s is not ignored\n" % f) |
2473 | 2480 |
2474 @command('debugindex', debugrevlogopts + | 2481 @command('debugindex', debugrevlogopts + |
2475 [('f', 'format', 0, _('revlog format'), _('FORMAT'))], | 2482 [('f', 'format', 0, _('revlog format'), _('FORMAT'))], |