##// END OF EJS Templates
purge: use absolute_import
timeless -
r28382:27996f78 default
parent child Browse files
Show More
@@ -1,119 +1,127
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
27
27 from mercurial import util, commands, cmdutil, scmutil, error
28 import os
29
30 from mercurial import (
31 cmdutil,
32 commands,
33 error,
34 scmutil,
35 util,
36 )
28 from mercurial.i18n import _
37 from mercurial.i18n import _
29 import os
30
38
31 cmdtable = {}
39 cmdtable = {}
32 command = cmdutil.command(cmdtable)
40 command = cmdutil.command(cmdtable)
33 # Note for extension authors: ONLY specify testedwith = 'internal' for
41 # Note for extension authors: ONLY specify testedwith = 'internal' for
34 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
42 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
35 # be specifying the version(s) of Mercurial they are tested with, or
43 # be specifying the version(s) of Mercurial they are tested with, or
36 # leave the attribute unspecified.
44 # leave the attribute unspecified.
37 testedwith = 'internal'
45 testedwith = 'internal'
38
46
39 @command('purge|clean',
47 @command('purge|clean',
40 [('a', 'abort-on-err', None, _('abort if an error occurs')),
48 [('a', 'abort-on-err', None, _('abort if an error occurs')),
41 ('', 'all', None, _('purge ignored files too')),
49 ('', 'all', None, _('purge ignored files too')),
42 ('', 'dirs', None, _('purge empty directories')),
50 ('', 'dirs', None, _('purge empty directories')),
43 ('', 'files', None, _('purge files')),
51 ('', 'files', None, _('purge files')),
44 ('p', 'print', None, _('print filenames instead of deleting them')),
52 ('p', 'print', None, _('print filenames instead of deleting them')),
45 ('0', 'print0', None, _('end filenames with NUL, for use with xargs'
53 ('0', 'print0', None, _('end filenames with NUL, for use with xargs'
46 ' (implies -p/--print)')),
54 ' (implies -p/--print)')),
47 ] + commands.walkopts,
55 ] + commands.walkopts,
48 _('hg purge [OPTION]... [DIR]...'))
56 _('hg purge [OPTION]... [DIR]...'))
49 def purge(ui, repo, *dirs, **opts):
57 def purge(ui, repo, *dirs, **opts):
50 '''removes files not tracked by Mercurial
58 '''removes files not tracked by Mercurial
51
59
52 Delete files not known to Mercurial. This is useful to test local
60 Delete files not known to Mercurial. This is useful to test local
53 and uncommitted changes in an otherwise-clean source tree.
61 and uncommitted changes in an otherwise-clean source tree.
54
62
55 This means that purge will delete the following by default:
63 This means that purge will delete the following by default:
56
64
57 - Unknown files: files marked with "?" by :hg:`status`
65 - Unknown files: files marked with "?" by :hg:`status`
58 - Empty directories: in fact Mercurial ignores directories unless
66 - Empty directories: in fact Mercurial ignores directories unless
59 they contain files under source control management
67 they contain files under source control management
60
68
61 But it will leave untouched:
69 But it will leave untouched:
62
70
63 - Modified and unmodified tracked files
71 - Modified and unmodified tracked files
64 - Ignored files (unless --all is specified)
72 - Ignored files (unless --all is specified)
65 - New files added to the repository (with :hg:`add`)
73 - New files added to the repository (with :hg:`add`)
66
74
67 The --files and --dirs options can be used to direct purge to delete
75 The --files and --dirs options can be used to direct purge to delete
68 only files, only directories, or both. If neither option is given,
76 only files, only directories, or both. If neither option is given,
69 both will be deleted.
77 both will be deleted.
70
78
71 If directories are given on the command line, only files in these
79 If directories are given on the command line, only files in these
72 directories are considered.
80 directories are considered.
73
81
74 Be careful with purge, as you could irreversibly delete some files
82 Be careful with purge, as you could irreversibly delete some files
75 you forgot to add to the repository. If you only want to print the
83 you forgot to add to the repository. If you only want to print the
76 list of files that this program would delete, use the --print
84 list of files that this program would delete, use the --print
77 option.
85 option.
78 '''
86 '''
79 act = not opts['print']
87 act = not opts['print']
80 eol = '\n'
88 eol = '\n'
81 if opts['print0']:
89 if opts['print0']:
82 eol = '\0'
90 eol = '\0'
83 act = False # --print0 implies --print
91 act = False # --print0 implies --print
84 removefiles = opts['files']
92 removefiles = opts['files']
85 removedirs = opts['dirs']
93 removedirs = opts['dirs']
86 if not removefiles and not removedirs:
94 if not removefiles and not removedirs:
87 removefiles = True
95 removefiles = True
88 removedirs = True
96 removedirs = True
89
97
90 def remove(remove_func, name):
98 def remove(remove_func, name):
91 if act:
99 if act:
92 try:
100 try:
93 remove_func(repo.wjoin(name))
101 remove_func(repo.wjoin(name))
94 except OSError:
102 except OSError:
95 m = _('%s cannot be removed') % name
103 m = _('%s cannot be removed') % name
96 if opts['abort_on_err']:
104 if opts['abort_on_err']:
97 raise error.Abort(m)
105 raise error.Abort(m)
98 ui.warn(_('warning: %s\n') % m)
106 ui.warn(_('warning: %s\n') % m)
99 else:
107 else:
100 ui.write('%s%s' % (name, eol))
108 ui.write('%s%s' % (name, eol))
101
109
102 match = scmutil.match(repo[None], dirs, opts)
110 match = scmutil.match(repo[None], dirs, opts)
103 if removedirs:
111 if removedirs:
104 directories = []
112 directories = []
105 match.explicitdir = match.traversedir = directories.append
113 match.explicitdir = match.traversedir = directories.append
106 status = repo.status(match=match, ignored=opts['all'], unknown=True)
114 status = repo.status(match=match, ignored=opts['all'], unknown=True)
107
115
108 if removefiles:
116 if removefiles:
109 for f in sorted(status.unknown + status.ignored):
117 for f in sorted(status.unknown + status.ignored):
110 if act:
118 if act:
111 ui.note(_('removing file %s\n') % f)
119 ui.note(_('removing file %s\n') % f)
112 remove(util.unlink, f)
120 remove(util.unlink, f)
113
121
114 if removedirs:
122 if removedirs:
115 for f in sorted(directories, reverse=True):
123 for f in sorted(directories, reverse=True):
116 if match(f) and not os.listdir(repo.wjoin(f)):
124 if match(f) and not os.listdir(repo.wjoin(f)):
117 if act:
125 if act:
118 ui.note(_('removing directory %s\n') % f)
126 ui.note(_('removing directory %s\n') % f)
119 remove(os.rmdir, f)
127 remove(os.rmdir, f)
@@ -1,145 +1,144
1 #require test-repo
1 #require test-repo
2
2
3 $ cd "$TESTDIR"/..
3 $ cd "$TESTDIR"/..
4
4
5 $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs python contrib/check-py3-compat.py
5 $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs python contrib/check-py3-compat.py
6 contrib/check-code.py not using absolute_import
6 contrib/check-code.py not using absolute_import
7 contrib/check-code.py requires print_function
7 contrib/check-code.py requires print_function
8 contrib/debugshell.py not using absolute_import
8 contrib/debugshell.py not using absolute_import
9 contrib/hgfixes/fix_bytes.py not using absolute_import
9 contrib/hgfixes/fix_bytes.py not using absolute_import
10 contrib/hgfixes/fix_bytesmod.py not using absolute_import
10 contrib/hgfixes/fix_bytesmod.py not using absolute_import
11 contrib/hgfixes/fix_leftover_imports.py not using absolute_import
11 contrib/hgfixes/fix_leftover_imports.py not using absolute_import
12 contrib/import-checker.py not using absolute_import
12 contrib/import-checker.py not using absolute_import
13 contrib/import-checker.py requires print_function
13 contrib/import-checker.py requires print_function
14 contrib/memory.py not using absolute_import
14 contrib/memory.py not using absolute_import
15 contrib/perf.py not using absolute_import
15 contrib/perf.py not using absolute_import
16 contrib/python-hook-examples.py not using absolute_import
16 contrib/python-hook-examples.py not using absolute_import
17 contrib/revsetbenchmarks.py not using absolute_import
17 contrib/revsetbenchmarks.py not using absolute_import
18 contrib/revsetbenchmarks.py requires print_function
18 contrib/revsetbenchmarks.py requires print_function
19 contrib/showstack.py not using absolute_import
19 contrib/showstack.py not using absolute_import
20 contrib/synthrepo.py not using absolute_import
20 contrib/synthrepo.py not using absolute_import
21 contrib/win32/hgwebdir_wsgi.py not using absolute_import
21 contrib/win32/hgwebdir_wsgi.py not using absolute_import
22 doc/check-seclevel.py not using absolute_import
22 doc/check-seclevel.py not using absolute_import
23 doc/gendoc.py not using absolute_import
23 doc/gendoc.py not using absolute_import
24 doc/hgmanpage.py not using absolute_import
24 doc/hgmanpage.py not using absolute_import
25 hgext/__init__.py not using absolute_import
25 hgext/__init__.py not using absolute_import
26 hgext/color.py not using absolute_import
26 hgext/color.py not using absolute_import
27 hgext/convert/__init__.py not using absolute_import
27 hgext/convert/__init__.py not using absolute_import
28 hgext/convert/bzr.py not using absolute_import
28 hgext/convert/bzr.py not using absolute_import
29 hgext/convert/common.py not using absolute_import
29 hgext/convert/common.py not using absolute_import
30 hgext/convert/convcmd.py not using absolute_import
30 hgext/convert/convcmd.py not using absolute_import
31 hgext/convert/cvs.py not using absolute_import
31 hgext/convert/cvs.py not using absolute_import
32 hgext/convert/subversion.py not using absolute_import
32 hgext/convert/subversion.py not using absolute_import
33 hgext/convert/transport.py not using absolute_import
33 hgext/convert/transport.py not using absolute_import
34 hgext/eol.py not using absolute_import
34 hgext/eol.py not using absolute_import
35 hgext/extdiff.py not using absolute_import
35 hgext/extdiff.py not using absolute_import
36 hgext/factotum.py not using absolute_import
36 hgext/factotum.py not using absolute_import
37 hgext/fetch.py not using absolute_import
37 hgext/fetch.py not using absolute_import
38 hgext/gpg.py not using absolute_import
38 hgext/gpg.py not using absolute_import
39 hgext/graphlog.py not using absolute_import
39 hgext/graphlog.py not using absolute_import
40 hgext/hgcia.py not using absolute_import
40 hgext/hgcia.py not using absolute_import
41 hgext/hgk.py not using absolute_import
41 hgext/hgk.py not using absolute_import
42 hgext/highlight/__init__.py not using absolute_import
42 hgext/highlight/__init__.py not using absolute_import
43 hgext/highlight/highlight.py not using absolute_import
43 hgext/highlight/highlight.py not using absolute_import
44 hgext/histedit.py not using absolute_import
44 hgext/histedit.py not using absolute_import
45 hgext/largefiles/__init__.py not using absolute_import
45 hgext/largefiles/__init__.py not using absolute_import
46 hgext/largefiles/basestore.py not using absolute_import
46 hgext/largefiles/basestore.py not using absolute_import
47 hgext/largefiles/lfcommands.py not using absolute_import
47 hgext/largefiles/lfcommands.py not using absolute_import
48 hgext/largefiles/lfutil.py not using absolute_import
48 hgext/largefiles/lfutil.py not using absolute_import
49 hgext/largefiles/localstore.py not using absolute_import
49 hgext/largefiles/localstore.py not using absolute_import
50 hgext/largefiles/overrides.py not using absolute_import
50 hgext/largefiles/overrides.py not using absolute_import
51 hgext/largefiles/proto.py not using absolute_import
51 hgext/largefiles/proto.py not using absolute_import
52 hgext/largefiles/remotestore.py not using absolute_import
52 hgext/largefiles/remotestore.py not using absolute_import
53 hgext/largefiles/reposetup.py not using absolute_import
53 hgext/largefiles/reposetup.py not using absolute_import
54 hgext/largefiles/uisetup.py not using absolute_import
54 hgext/largefiles/uisetup.py not using absolute_import
55 hgext/largefiles/wirestore.py not using absolute_import
55 hgext/largefiles/wirestore.py not using absolute_import
56 hgext/mq.py not using absolute_import
56 hgext/mq.py not using absolute_import
57 hgext/notify.py not using absolute_import
57 hgext/notify.py not using absolute_import
58 hgext/patchbomb.py not using absolute_import
58 hgext/patchbomb.py not using absolute_import
59 hgext/purge.py not using absolute_import
60 hgext/rebase.py not using absolute_import
59 hgext/rebase.py not using absolute_import
61 hgext/share.py not using absolute_import
60 hgext/share.py not using absolute_import
62 hgext/transplant.py not using absolute_import
61 hgext/transplant.py not using absolute_import
63 hgext/win32mbcs.py not using absolute_import
62 hgext/win32mbcs.py not using absolute_import
64 hgext/win32text.py not using absolute_import
63 hgext/win32text.py not using absolute_import
65 i18n/check-translation.py not using absolute_import
64 i18n/check-translation.py not using absolute_import
66 i18n/polib.py not using absolute_import
65 i18n/polib.py not using absolute_import
67 setup.py not using absolute_import
66 setup.py not using absolute_import
68 tests/filterpyflakes.py requires print_function
67 tests/filterpyflakes.py requires print_function
69 tests/generate-working-copy-states.py requires print_function
68 tests/generate-working-copy-states.py requires print_function
70 tests/get-with-headers.py requires print_function
69 tests/get-with-headers.py requires print_function
71 tests/heredoctest.py requires print_function
70 tests/heredoctest.py requires print_function
72 tests/hypothesishelpers.py not using absolute_import
71 tests/hypothesishelpers.py not using absolute_import
73 tests/hypothesishelpers.py requires print_function
72 tests/hypothesishelpers.py requires print_function
74 tests/killdaemons.py not using absolute_import
73 tests/killdaemons.py not using absolute_import
75 tests/md5sum.py not using absolute_import
74 tests/md5sum.py not using absolute_import
76 tests/mockblackbox.py not using absolute_import
75 tests/mockblackbox.py not using absolute_import
77 tests/printenv.py not using absolute_import
76 tests/printenv.py not using absolute_import
78 tests/readlink.py not using absolute_import
77 tests/readlink.py not using absolute_import
79 tests/readlink.py requires print_function
78 tests/readlink.py requires print_function
80 tests/revlog-formatv0.py not using absolute_import
79 tests/revlog-formatv0.py not using absolute_import
81 tests/run-tests.py not using absolute_import
80 tests/run-tests.py not using absolute_import
82 tests/seq.py not using absolute_import
81 tests/seq.py not using absolute_import
83 tests/seq.py requires print_function
82 tests/seq.py requires print_function
84 tests/silenttestrunner.py not using absolute_import
83 tests/silenttestrunner.py not using absolute_import
85 tests/silenttestrunner.py requires print_function
84 tests/silenttestrunner.py requires print_function
86 tests/sitecustomize.py not using absolute_import
85 tests/sitecustomize.py not using absolute_import
87 tests/svn-safe-append.py not using absolute_import
86 tests/svn-safe-append.py not using absolute_import
88 tests/svnxml.py not using absolute_import
87 tests/svnxml.py not using absolute_import
89 tests/test-ancestor.py requires print_function
88 tests/test-ancestor.py requires print_function
90 tests/test-atomictempfile.py not using absolute_import
89 tests/test-atomictempfile.py not using absolute_import
91 tests/test-batching.py not using absolute_import
90 tests/test-batching.py not using absolute_import
92 tests/test-batching.py requires print_function
91 tests/test-batching.py requires print_function
93 tests/test-bdiff.py not using absolute_import
92 tests/test-bdiff.py not using absolute_import
94 tests/test-bdiff.py requires print_function
93 tests/test-bdiff.py requires print_function
95 tests/test-context.py not using absolute_import
94 tests/test-context.py not using absolute_import
96 tests/test-context.py requires print_function
95 tests/test-context.py requires print_function
97 tests/test-demandimport.py not using absolute_import
96 tests/test-demandimport.py not using absolute_import
98 tests/test-demandimport.py requires print_function
97 tests/test-demandimport.py requires print_function
99 tests/test-dispatch.py not using absolute_import
98 tests/test-dispatch.py not using absolute_import
100 tests/test-dispatch.py requires print_function
99 tests/test-dispatch.py requires print_function
101 tests/test-doctest.py not using absolute_import
100 tests/test-doctest.py not using absolute_import
102 tests/test-duplicateoptions.py not using absolute_import
101 tests/test-duplicateoptions.py not using absolute_import
103 tests/test-duplicateoptions.py requires print_function
102 tests/test-duplicateoptions.py requires print_function
104 tests/test-filecache.py not using absolute_import
103 tests/test-filecache.py not using absolute_import
105 tests/test-filecache.py requires print_function
104 tests/test-filecache.py requires print_function
106 tests/test-filelog.py not using absolute_import
105 tests/test-filelog.py not using absolute_import
107 tests/test-filelog.py requires print_function
106 tests/test-filelog.py requires print_function
108 tests/test-hg-parseurl.py not using absolute_import
107 tests/test-hg-parseurl.py not using absolute_import
109 tests/test-hg-parseurl.py requires print_function
108 tests/test-hg-parseurl.py requires print_function
110 tests/test-hgweb-auth.py not using absolute_import
109 tests/test-hgweb-auth.py not using absolute_import
111 tests/test-hgweb-auth.py requires print_function
110 tests/test-hgweb-auth.py requires print_function
112 tests/test-hgwebdir-paths.py not using absolute_import
111 tests/test-hgwebdir-paths.py not using absolute_import
113 tests/test-hybridencode.py not using absolute_import
112 tests/test-hybridencode.py not using absolute_import
114 tests/test-hybridencode.py requires print_function
113 tests/test-hybridencode.py requires print_function
115 tests/test-lrucachedict.py not using absolute_import
114 tests/test-lrucachedict.py not using absolute_import
116 tests/test-lrucachedict.py requires print_function
115 tests/test-lrucachedict.py requires print_function
117 tests/test-manifest.py not using absolute_import
116 tests/test-manifest.py not using absolute_import
118 tests/test-minirst.py not using absolute_import
117 tests/test-minirst.py not using absolute_import
119 tests/test-minirst.py requires print_function
118 tests/test-minirst.py requires print_function
120 tests/test-parseindex2.py not using absolute_import
119 tests/test-parseindex2.py not using absolute_import
121 tests/test-parseindex2.py requires print_function
120 tests/test-parseindex2.py requires print_function
122 tests/test-pathencode.py not using absolute_import
121 tests/test-pathencode.py not using absolute_import
123 tests/test-pathencode.py requires print_function
122 tests/test-pathencode.py requires print_function
124 tests/test-propertycache.py not using absolute_import
123 tests/test-propertycache.py not using absolute_import
125 tests/test-propertycache.py requires print_function
124 tests/test-propertycache.py requires print_function
126 tests/test-revlog-ancestry.py not using absolute_import
125 tests/test-revlog-ancestry.py not using absolute_import
127 tests/test-revlog-ancestry.py requires print_function
126 tests/test-revlog-ancestry.py requires print_function
128 tests/test-run-tests.py not using absolute_import
127 tests/test-run-tests.py not using absolute_import
129 tests/test-simplemerge.py not using absolute_import
128 tests/test-simplemerge.py not using absolute_import
130 tests/test-status-inprocess.py not using absolute_import
129 tests/test-status-inprocess.py not using absolute_import
131 tests/test-status-inprocess.py requires print_function
130 tests/test-status-inprocess.py requires print_function
132 tests/test-symlink-os-yes-fs-no.py not using absolute_import
131 tests/test-symlink-os-yes-fs-no.py not using absolute_import
133 tests/test-trusted.py not using absolute_import
132 tests/test-trusted.py not using absolute_import
134 tests/test-trusted.py requires print_function
133 tests/test-trusted.py requires print_function
135 tests/test-ui-color.py not using absolute_import
134 tests/test-ui-color.py not using absolute_import
136 tests/test-ui-color.py requires print_function
135 tests/test-ui-color.py requires print_function
137 tests/test-ui-config.py not using absolute_import
136 tests/test-ui-config.py not using absolute_import
138 tests/test-ui-config.py requires print_function
137 tests/test-ui-config.py requires print_function
139 tests/test-ui-verbosity.py not using absolute_import
138 tests/test-ui-verbosity.py not using absolute_import
140 tests/test-ui-verbosity.py requires print_function
139 tests/test-ui-verbosity.py requires print_function
141 tests/test-url.py not using absolute_import
140 tests/test-url.py not using absolute_import
142 tests/test-url.py requires print_function
141 tests/test-url.py requires print_function
143 tests/test-walkrepo.py requires print_function
142 tests/test-walkrepo.py requires print_function
144 tests/test-wireproto.py requires print_function
143 tests/test-wireproto.py requires print_function
145 tests/tinyproxy.py requires print_function
144 tests/tinyproxy.py requires print_function
General Comments 0
You need to be logged in to leave comments. Login now