Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 46368:bb3a5c0df06b
purge: move extension into core mercurial
The motivation is simple: it's nicer to avoid gating basic
functionality.
To reduce the risk of people shooting themselves in the feet, `--confirm` is now
the default, unless the extensions is loaded..
For review of the body of the purge command, use this instead of what
hg/phabricator will show (the block of code is modified, not just
moved):
Differential Revision: https://phab.mercurial-scm.org/D9820
author | Valentin Gatien-Baron <valentin.gatienbaron@gmail.com> |
---|---|
date | Mon, 18 Jan 2021 10:24:20 +0100 |
parents | dfca84970da8 |
children | 16c18d5e5dc8 |
comparison
equal
deleted
inserted
replaced
46367:57370e7deb7b | 46368:bb3a5c0df06b |
---|---|
5445 other.close() | 5445 other.close() |
5446 return ret | 5446 return ret |
5447 | 5447 |
5448 | 5448 |
5449 @command( | 5449 @command( |
5450 b'purge|clean', | |
5451 [ | |
5452 (b'a', b'abort-on-err', None, _(b'abort if an error occurs')), | |
5453 (b'', b'all', None, _(b'purge ignored files too')), | |
5454 (b'i', b'ignored', None, _(b'purge only ignored files')), | |
5455 (b'', b'dirs', None, _(b'purge empty directories')), | |
5456 (b'', b'files', None, _(b'purge files')), | |
5457 (b'p', b'print', None, _(b'print filenames instead of deleting them')), | |
5458 ( | |
5459 b'0', | |
5460 b'print0', | |
5461 None, | |
5462 _( | |
5463 b'end filenames with NUL, for use with xargs' | |
5464 b' (implies -p/--print)' | |
5465 ), | |
5466 ), | |
5467 (b'', b'confirm', None, _(b'ask before permanently deleting files')), | |
5468 ] | |
5469 + cmdutil.walkopts, | |
5470 _(b'hg purge [OPTION]... [DIR]...'), | |
5471 helpcategory=command.CATEGORY_WORKING_DIRECTORY, | |
5472 ) | |
5473 def purge(ui, repo, *dirs, **opts): | |
5474 """removes files not tracked by Mercurial | |
5475 | |
5476 Delete files not known to Mercurial. This is useful to test local | |
5477 and uncommitted changes in an otherwise-clean source tree. | |
5478 | |
5479 This means that purge will delete the following by default: | |
5480 | |
5481 - Unknown files: files marked with "?" by :hg:`status` | |
5482 - Empty directories: in fact Mercurial ignores directories unless | |
5483 they contain files under source control management | |
5484 | |
5485 But it will leave untouched: | |
5486 | |
5487 - Modified and unmodified tracked files | |
5488 - Ignored files (unless -i or --all is specified) | |
5489 - New files added to the repository (with :hg:`add`) | |
5490 | |
5491 The --files and --dirs options can be used to direct purge to delete | |
5492 only files, only directories, or both. If neither option is given, | |
5493 both will be deleted. | |
5494 | |
5495 If directories are given on the command line, only files in these | |
5496 directories are considered. | |
5497 | |
5498 Be careful with purge, as you could irreversibly delete some files | |
5499 you forgot to add to the repository. If you only want to print the | |
5500 list of files that this program would delete, use the --print | |
5501 option. | |
5502 """ | |
5503 opts = pycompat.byteskwargs(opts) | |
5504 cmdutil.check_at_most_one_arg(opts, b'all', b'ignored') | |
5505 | |
5506 act = not opts.get(b'print') | |
5507 eol = b'\n' | |
5508 if opts.get(b'print0'): | |
5509 eol = b'\0' | |
5510 act = False # --print0 implies --print | |
5511 if opts.get(b'all', False): | |
5512 ignored = True | |
5513 unknown = True | |
5514 else: | |
5515 ignored = opts.get(b'ignored', False) | |
5516 unknown = not ignored | |
5517 | |
5518 removefiles = opts.get(b'files') | |
5519 removedirs = opts.get(b'dirs') | |
5520 confirm = opts.get(b'confirm') | |
5521 if confirm is None: | |
5522 try: | |
5523 extensions.find(b'purge') | |
5524 confirm = False | |
5525 except KeyError: | |
5526 confirm = True | |
5527 | |
5528 if not removefiles and not removedirs: | |
5529 removefiles = True | |
5530 removedirs = True | |
5531 | |
5532 match = scmutil.match(repo[None], dirs, opts) | |
5533 | |
5534 paths = mergemod.purge( | |
5535 repo, | |
5536 match, | |
5537 unknown=unknown, | |
5538 ignored=ignored, | |
5539 removeemptydirs=removedirs, | |
5540 removefiles=removefiles, | |
5541 abortonerror=opts.get(b'abort_on_err'), | |
5542 noop=not act, | |
5543 confirm=confirm, | |
5544 ) | |
5545 | |
5546 for path in paths: | |
5547 if not act: | |
5548 ui.write(b'%s%s' % (path, eol)) | |
5549 | |
5550 | |
5551 @command( | |
5450 b'push', | 5552 b'push', |
5451 [ | 5553 [ |
5452 (b'f', b'force', None, _(b'force push')), | 5554 (b'f', b'force', None, _(b'force push')), |
5453 ( | 5555 ( |
5454 b'r', | 5556 b'r', |