##// END OF EJS Templates
purge: move extension into core mercurial...
Valentin Gatien-Baron -
r47080:bb3a5c0d default
parent child Browse files
Show More
@@ -1567,7 +1567,7 def scmutiladdremove(orig, repo, matcher
1567
1567
1568 # Calling purge with --all will cause the largefiles to be deleted.
1568 # Calling purge with --all will cause the largefiles to be deleted.
1569 # Override repo.status to prevent this from happening.
1569 # Override repo.status to prevent this from happening.
1570 @eh.wrapcommand(b'purge', extension=b'purge')
1570 @eh.wrapcommand(b'purge')
1571 def overridepurge(orig, ui, repo, *dirs, **opts):
1571 def overridepurge(orig, ui, repo, *dirs, **opts):
1572 # XXX Monkey patching a repoview will not work. The assigned attribute will
1572 # XXX Monkey patching a repoview will not work. The assigned attribute will
1573 # be set on the unfiltered repo, but we will only lookup attributes in the
1573 # be set on the unfiltered repo, but we will only lookup attributes in the
@@ -22,118 +22,11
22 # You should have received a copy of the GNU General Public License
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, see <http://www.gnu.org/licenses/>.
23 # along with this program; if not, see <http://www.gnu.org/licenses/>.
24
24
25 '''command to delete untracked files from the working directory'''
25 '''command to delete untracked files from the working directory (DEPRECATED)
26 from __future__ import absolute_import
27
28 from mercurial.i18n import _
29 from mercurial import (
30 cmdutil,
31 merge as mergemod,
32 pycompat,
33 registrar,
34 scmutil,
35 )
36
37 cmdtable = {}
38 command = registrar.command(cmdtable)
39 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
40 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
41 # be specifying the version(s) of Mercurial they are tested with, or
42 # leave the attribute unspecified.
43 testedwith = b'ships-with-hg-core'
44
45
46 @command(
47 b'purge|clean',
48 [
49 (b'a', b'abort-on-err', None, _(b'abort if an error occurs')),
50 (b'', b'all', None, _(b'purge ignored files too')),
51 (b'i', b'ignored', None, _(b'purge only ignored files')),
52 (b'', b'dirs', None, _(b'purge empty directories')),
53 (b'', b'files', None, _(b'purge files')),
54 (b'p', b'print', None, _(b'print filenames instead of deleting them')),
55 (
56 b'0',
57 b'print0',
58 None,
59 _(
60 b'end filenames with NUL, for use with xargs'
61 b' (implies -p/--print)'
62 ),
63 ),
64 (b'', b'confirm', None, _(b'ask before permanently deleting files')),
65 ]
66 + cmdutil.walkopts,
67 _(b'hg purge [OPTION]... [DIR]...'),
68 helpcategory=command.CATEGORY_WORKING_DIRECTORY,
69 )
70 def purge(ui, repo, *dirs, **opts):
71 """removes files not tracked by Mercurial
72
73 Delete files not known to Mercurial. This is useful to test local
74 and uncommitted changes in an otherwise-clean source tree.
75
76 This means that purge will delete the following by default:
77
78 - Unknown files: files marked with "?" by :hg:`status`
79 - Empty directories: in fact Mercurial ignores directories unless
80 they contain files under source control management
81
26
82 But it will leave untouched:
27 The functionality of this extension has been included in core Mercurial since
83
28 version 5.7. Please use :hg:`purge ...` instead. :hg:`purge --confirm` is now the default, unless the extension is enabled for backward compatibility.
84 - Modified and unmodified tracked files
29 '''
85 - Ignored files (unless -i or --all is specified)
86 - New files added to the repository (with :hg:`add`)
87
88 The --files and --dirs options can be used to direct purge to delete
89 only files, only directories, or both. If neither option is given,
90 both will be deleted.
91
92 If directories are given on the command line, only files in these
93 directories are considered.
94
95 Be careful with purge, as you could irreversibly delete some files
96 you forgot to add to the repository. If you only want to print the
97 list of files that this program would delete, use the --print
98 option.
99 """
100 opts = pycompat.byteskwargs(opts)
101 cmdutil.check_at_most_one_arg(opts, b'all', b'ignored')
102
30
103 act = not opts.get(b'print')
31 # This empty extension looks pointless, but core mercurial checks if it's loaded
104 eol = b'\n'
32 # to implement the slightly different behavior documented above.
105 if opts.get(b'print0'):
106 eol = b'\0'
107 act = False # --print0 implies --print
108 if opts.get(b'all', False):
109 ignored = True
110 unknown = True
111 else:
112 ignored = opts.get(b'ignored', False)
113 unknown = not ignored
114
115 removefiles = opts.get(b'files')
116 removedirs = opts.get(b'dirs')
117 confirm = opts.get(b'confirm')
118
119 if not removefiles and not removedirs:
120 removefiles = True
121 removedirs = True
122
123 match = scmutil.match(repo[None], dirs, opts)
124
125 paths = mergemod.purge(
126 repo,
127 match,
128 unknown=unknown,
129 ignored=ignored,
130 removeemptydirs=removedirs,
131 removefiles=removefiles,
132 abortonerror=opts.get(b'abort_on_err'),
133 noop=not act,
134 confirm=confirm,
135 )
136
137 for path in paths:
138 if not act:
139 ui.write(b'%s%s' % (path, eol))
@@ -5447,6 +5447,108 def pull(ui, repo, source=b"default", **
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')),
@@ -17,6 +17,8
17 can be e.g. `rebase`. As part of this effort, the default format
17 can be e.g. `rebase`. As part of this effort, the default format
18 from `hg rebase` was reorganized a bit.
18 from `hg rebase` was reorganized a bit.
19
19
20 * `hg purge` is now a core command using `--confirm` by default.
21
20 * `hg strip`, from the strip extension, is now a core command, `hg
22 * `hg strip`, from the strip extension, is now a core command, `hg
21 debugstrip`. The extension remains for compatibility.
23 debugstrip`. The extension remains for compatibility.
22
24
@@ -38,6 +38,7 Show all commands except debug commands
38 paths
38 paths
39 phase
39 phase
40 pull
40 pull
41 purge
41 push
42 push
42 recover
43 recover
43 remove
44 remove
@@ -354,6 +355,7 Show all commands + options
354 paths: template
355 paths: template
355 phase: public, draft, secret, force, rev
356 phase: public, draft, secret, force, rev
356 pull: update, force, confirm, rev, bookmark, branch, ssh, remotecmd, insecure
357 pull: update, force, confirm, rev, bookmark, branch, ssh, remotecmd, insecure
358 purge: abort-on-err, all, ignored, dirs, files, print, print0, confirm, include, exclude
357 push: force, rev, bookmark, all-bookmarks, branch, new-branch, pushvars, publish, ssh, remotecmd, insecure
359 push: force, rev, bookmark, all-bookmarks, branch, new-branch, pushvars, publish, ssh, remotecmd, insecure
358 recover: verify
360 recover: verify
359 remove: after, force, subrepos, include, exclude, dry-run
361 remove: after, force, subrepos, include, exclude, dry-run
@@ -351,6 +351,7 Testing -h/--help:
351 addremove add all new files, delete all missing files
351 addremove add all new files, delete all missing files
352 files list tracked files
352 files list tracked files
353 forget forget the specified files on the next commit
353 forget forget the specified files on the next commit
354 purge removes files not tracked by Mercurial
354 remove remove the specified files on the next commit
355 remove remove the specified files on the next commit
355 rename rename files; equivalent of copy + remove
356 rename rename files; equivalent of copy + remove
356 resolve redo merges or set/view the merge status of files
357 resolve redo merges or set/view the merge status of files
@@ -483,6 +484,7 Testing -h/--help:
483 addremove add all new files, delete all missing files
484 addremove add all new files, delete all missing files
484 files list tracked files
485 files list tracked files
485 forget forget the specified files on the next commit
486 forget forget the specified files on the next commit
487 purge removes files not tracked by Mercurial
486 remove remove the specified files on the next commit
488 remove remove the specified files on the next commit
487 rename rename files; equivalent of copy + remove
489 rename rename files; equivalent of copy + remove
488 resolve redo merges or set/view the merge status of files
490 resolve redo merges or set/view the merge status of files
@@ -55,6 +55,7 Test hiding some commands (which also ha
55 addremove add all new files, delete all missing files
55 addremove add all new files, delete all missing files
56 files list tracked files
56 files list tracked files
57 forget forget the specified files on the next commit
57 forget forget the specified files on the next commit
58 purge removes files not tracked by Mercurial
58 remove remove the specified files on the next commit
59 remove remove the specified files on the next commit
59 rename rename files; equivalent of copy + remove
60 rename rename files; equivalent of copy + remove
60 resolve redo merges or set/view the merge status of files
61 resolve redo merges or set/view the merge status of files
@@ -191,6 +192,7 Test hiding some topics.
191 addremove add all new files, delete all missing files
192 addremove add all new files, delete all missing files
192 files list tracked files
193 files list tracked files
193 forget forget the specified files on the next commit
194 forget forget the specified files on the next commit
195 purge removes files not tracked by Mercurial
194 remove remove the specified files on the next commit
196 remove remove the specified files on the next commit
195 rename rename files; equivalent of copy + remove
197 rename rename files; equivalent of copy + remove
196 resolve redo merges or set/view the merge status of files
198 resolve redo merges or set/view the merge status of files
@@ -107,6 +107,7 the extension is unknown.
107 addremove add all new files, delete all missing files
107 addremove add all new files, delete all missing files
108 files list tracked files
108 files list tracked files
109 forget forget the specified files on the next commit
109 forget forget the specified files on the next commit
110 purge removes files not tracked by Mercurial
110 remove remove the specified files on the next commit
111 remove remove the specified files on the next commit
111 rename rename files; equivalent of copy + remove
112 rename rename files; equivalent of copy + remove
112 resolve redo merges or set/view the merge status of files
113 resolve redo merges or set/view the merge status of files
@@ -235,6 +236,7 the extension is unknown.
235 addremove add all new files, delete all missing files
236 addremove add all new files, delete all missing files
236 files list tracked files
237 files list tracked files
237 forget forget the specified files on the next commit
238 forget forget the specified files on the next commit
239 purge removes files not tracked by Mercurial
238 remove remove the specified files on the next commit
240 remove remove the specified files on the next commit
239 rename rename files; equivalent of copy + remove
241 rename rename files; equivalent of copy + remove
240 resolve redo merges or set/view the merge status of files
242 resolve redo merges or set/view the merge status of files
@@ -375,8 +377,6 Test extension help:
375 mq manage a stack of patches
377 mq manage a stack of patches
376 notify hooks for sending email push notifications
378 notify hooks for sending email push notifications
377 patchbomb command to send changesets as (a series of) patch emails
379 patchbomb command to send changesets as (a series of) patch emails
378 purge command to delete untracked files from the working
379 directory
380 relink recreates hardlinks between repository clones
380 relink recreates hardlinks between repository clones
381 schemes extend schemes with shortcuts to repository swarms
381 schemes extend schemes with shortcuts to repository swarms
382 share share a common history between several working directories
382 share share a common history between several working directories
@@ -2720,6 +2720,13 Dish up an empty repo; serve it cold.
2720 set or show the current phase name
2720 set or show the current phase name
2721 </td></tr>
2721 </td></tr>
2722 <tr><td>
2722 <tr><td>
2723 <a href="/help/purge">
2724 purge
2725 </a>
2726 </td><td>
2727 removes files not tracked by Mercurial
2728 </td></tr>
2729 <tr><td>
2723 <a href="/help/recover">
2730 <a href="/help/recover">
2724 recover
2731 recover
2725 </a>
2732 </a>
@@ -2190,6 +2190,10 help/ shows help topics
2190 "topic": "phase"
2190 "topic": "phase"
2191 },
2191 },
2192 {
2192 {
2193 "summary": "removes files not tracked by Mercurial",
2194 "topic": "purge"
2195 },
2196 {
2193 "summary": "roll back an interrupted transaction",
2197 "summary": "roll back an interrupted transaction",
2194 "topic": "recover"
2198 "topic": "recover"
2195 },
2199 },
@@ -1,8 +1,3
1 $ cat <<EOF >> $HGRCPATH
2 > [extensions]
3 > purge =
4 > EOF
5
6 init
1 init
7
2
8 $ hg init t
3 $ hg init t
@@ -18,6 +13,26 setup
18 $ echo 'ignored' > .hgignore
13 $ echo 'ignored' > .hgignore
19 $ hg ci -qAmr3 -d'2 0'
14 $ hg ci -qAmr3 -d'2 0'
20
15
16 purge without the extension
17
18 $ hg st
19 $ touch foo
20 $ hg purge
21 permanently delete 1 unkown files? (yN) n
22 abort: removal cancelled
23 [250]
24 $ hg st
25 ? foo
26 $ hg purge --no-confirm
27 $ hg st
28
29 now enabling the extension
30
31 $ cat <<EOF >> $HGRCPATH
32 > [extensions]
33 > purge =
34 > EOF
35
21 delete an empty directory
36 delete an empty directory
22
37
23 $ mkdir empty_dir
38 $ mkdir empty_dir
General Comments 0
You need to be logged in to leave comments. Login now