##// END OF EJS Templates
purge: classify as a "working directory management" command in help...
Martin von Zweigbergk -
r45693:81859d38 default
parent child Browse files
Show More
@@ -1,136 +1,136
1 # Copyright (C) 2006 - Marco Barisione <marco@barisione.org>
1 # Copyright (C) 2006 - Marco Barisione <marco@barisione.org>
2 #
2 #
3 # This is a small extension for Mercurial (https://mercurial-scm.org/)
3 # This is a small extension for Mercurial (https://mercurial-scm.org/)
4 # that removes files not known to mercurial
4 # that removes files not known to mercurial
5 #
5 #
6 # This program was inspired by the "cvspurge" script contained in CVS
6 # This program was inspired by the "cvspurge" script contained in CVS
7 # utilities (http://www.red-bean.com/cvsutils/).
7 # utilities (http://www.red-bean.com/cvsutils/).
8 #
8 #
9 # For help on the usage of "hg purge" use:
9 # For help on the usage of "hg purge" use:
10 # hg help purge
10 # hg help purge
11 #
11 #
12 # This program is free software; you can redistribute it and/or modify
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
15 # (at your option) any later version.
16 #
16 #
17 # This program is distributed in the hope that it will be useful,
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
20 # GNU General Public License for more details.
21 #
21 #
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'''
26 from __future__ import absolute_import
26 from __future__ import absolute_import
27
27
28 from mercurial.i18n import _
28 from mercurial.i18n import _
29 from mercurial import (
29 from mercurial import (
30 cmdutil,
30 cmdutil,
31 merge as mergemod,
31 merge as mergemod,
32 pycompat,
32 pycompat,
33 registrar,
33 registrar,
34 scmutil,
34 scmutil,
35 )
35 )
36
36
37 cmdtable = {}
37 cmdtable = {}
38 command = registrar.command(cmdtable)
38 command = registrar.command(cmdtable)
39 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
39 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
40 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
40 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
41 # be specifying the version(s) of Mercurial they are tested with, or
41 # be specifying the version(s) of Mercurial they are tested with, or
42 # leave the attribute unspecified.
42 # leave the attribute unspecified.
43 testedwith = b'ships-with-hg-core'
43 testedwith = b'ships-with-hg-core'
44
44
45
45
46 @command(
46 @command(
47 b'purge|clean',
47 b'purge|clean',
48 [
48 [
49 (b'a', b'abort-on-err', None, _(b'abort if an error occurs')),
49 (b'a', b'abort-on-err', None, _(b'abort if an error occurs')),
50 (b'', b'all', None, _(b'purge ignored files too')),
50 (b'', b'all', None, _(b'purge ignored files too')),
51 (b'i', b'ignored', None, _(b'purge only ignored files')),
51 (b'i', b'ignored', None, _(b'purge only ignored files')),
52 (b'', b'dirs', None, _(b'purge empty directories')),
52 (b'', b'dirs', None, _(b'purge empty directories')),
53 (b'', b'files', None, _(b'purge files')),
53 (b'', b'files', None, _(b'purge files')),
54 (b'p', b'print', None, _(b'print filenames instead of deleting them')),
54 (b'p', b'print', None, _(b'print filenames instead of deleting them')),
55 (
55 (
56 b'0',
56 b'0',
57 b'print0',
57 b'print0',
58 None,
58 None,
59 _(
59 _(
60 b'end filenames with NUL, for use with xargs'
60 b'end filenames with NUL, for use with xargs'
61 b' (implies -p/--print)'
61 b' (implies -p/--print)'
62 ),
62 ),
63 ),
63 ),
64 ]
64 ]
65 + cmdutil.walkopts,
65 + cmdutil.walkopts,
66 _(b'hg purge [OPTION]... [DIR]...'),
66 _(b'hg purge [OPTION]... [DIR]...'),
67 helpcategory=command.CATEGORY_MAINTENANCE,
67 helpcategory=command.CATEGORY_WORKING_DIRECTORY,
68 )
68 )
69 def purge(ui, repo, *dirs, **opts):
69 def purge(ui, repo, *dirs, **opts):
70 '''removes files not tracked by Mercurial
70 '''removes files not tracked by Mercurial
71
71
72 Delete files not known to Mercurial. This is useful to test local
72 Delete files not known to Mercurial. This is useful to test local
73 and uncommitted changes in an otherwise-clean source tree.
73 and uncommitted changes in an otherwise-clean source tree.
74
74
75 This means that purge will delete the following by default:
75 This means that purge will delete the following by default:
76
76
77 - Unknown files: files marked with "?" by :hg:`status`
77 - Unknown files: files marked with "?" by :hg:`status`
78 - Empty directories: in fact Mercurial ignores directories unless
78 - Empty directories: in fact Mercurial ignores directories unless
79 they contain files under source control management
79 they contain files under source control management
80
80
81 But it will leave untouched:
81 But it will leave untouched:
82
82
83 - Modified and unmodified tracked files
83 - Modified and unmodified tracked files
84 - Ignored files (unless -i or --all is specified)
84 - Ignored files (unless -i or --all is specified)
85 - New files added to the repository (with :hg:`add`)
85 - New files added to the repository (with :hg:`add`)
86
86
87 The --files and --dirs options can be used to direct purge to delete
87 The --files and --dirs options can be used to direct purge to delete
88 only files, only directories, or both. If neither option is given,
88 only files, only directories, or both. If neither option is given,
89 both will be deleted.
89 both will be deleted.
90
90
91 If directories are given on the command line, only files in these
91 If directories are given on the command line, only files in these
92 directories are considered.
92 directories are considered.
93
93
94 Be careful with purge, as you could irreversibly delete some files
94 Be careful with purge, as you could irreversibly delete some files
95 you forgot to add to the repository. If you only want to print the
95 you forgot to add to the repository. If you only want to print the
96 list of files that this program would delete, use the --print
96 list of files that this program would delete, use the --print
97 option.
97 option.
98 '''
98 '''
99 opts = pycompat.byteskwargs(opts)
99 opts = pycompat.byteskwargs(opts)
100 cmdutil.check_at_most_one_arg(opts, b'all', b'ignored')
100 cmdutil.check_at_most_one_arg(opts, b'all', b'ignored')
101
101
102 act = not opts.get(b'print')
102 act = not opts.get(b'print')
103 eol = b'\n'
103 eol = b'\n'
104 if opts.get(b'print0'):
104 if opts.get(b'print0'):
105 eol = b'\0'
105 eol = b'\0'
106 act = False # --print0 implies --print
106 act = False # --print0 implies --print
107 if opts.get(b'all', False):
107 if opts.get(b'all', False):
108 ignored = True
108 ignored = True
109 unknown = True
109 unknown = True
110 else:
110 else:
111 ignored = opts.get(b'ignored', False)
111 ignored = opts.get(b'ignored', False)
112 unknown = not ignored
112 unknown = not ignored
113
113
114 removefiles = opts.get(b'files')
114 removefiles = opts.get(b'files')
115 removedirs = opts.get(b'dirs')
115 removedirs = opts.get(b'dirs')
116
116
117 if not removefiles and not removedirs:
117 if not removefiles and not removedirs:
118 removefiles = True
118 removefiles = True
119 removedirs = True
119 removedirs = True
120
120
121 match = scmutil.match(repo[None], dirs, opts)
121 match = scmutil.match(repo[None], dirs, opts)
122
122
123 paths = mergemod.purge(
123 paths = mergemod.purge(
124 repo,
124 repo,
125 match,
125 match,
126 unknown=unknown,
126 unknown=unknown,
127 ignored=ignored,
127 ignored=ignored,
128 removeemptydirs=removedirs,
128 removeemptydirs=removedirs,
129 removefiles=removefiles,
129 removefiles=removefiles,
130 abortonerror=opts.get(b'abort_on_err'),
130 abortonerror=opts.get(b'abort_on_err'),
131 noop=not act,
131 noop=not act,
132 )
132 )
133
133
134 for path in paths:
134 for path in paths:
135 if not act:
135 if not act:
136 ui.write(b'%s%s' % (path, eol))
136 ui.write(b'%s%s' % (path, eol))
General Comments 0
You need to be logged in to leave comments. Login now