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 (DEPRECATED) |
26 from __future__ import absolute_import |
|
27 |
26 |
28 from mercurial.i18n import _ |
27 The functionality of this extension has been included in core Mercurial since |
29 from mercurial import ( |
28 version 5.7. Please use :hg:`purge ...` instead. :hg:`purge --confirm` is now the default, unless the extension is enabled for backward compatibility. |
30 cmdutil, |
29 ''' |
31 merge as mergemod, |
|
32 pycompat, |
|
33 registrar, |
|
34 scmutil, |
|
35 ) |
|
36 |
30 |
37 cmdtable = {} |
31 # This empty extension looks pointless, but core mercurial checks if it's loaded |
38 command = registrar.command(cmdtable) |
32 # to implement the slightly different behavior documented above. |
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 |
|
82 But it will leave untouched: |
|
83 |
|
84 - Modified and unmodified tracked files |
|
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 |
|
103 act = not opts.get(b'print') |
|
104 eol = b'\n' |
|
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)) |
|