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