##// END OF EJS Templates
purge: cleanup...
Matt Mackall -
r6757:55c71226 default
parent child Browse files
Show More
@@ -56,33 +56,24 b' def purge(ui, repo, *dirs, **opts):'
56 files that this program would delete use the --print option.
56 files that this program would delete use the --print option.
57 '''
57 '''
58 act = not opts['print']
58 act = not opts['print']
59 abort_on_err = bool(opts['abort_on_err'])
59 eol = '\n'
60 eol = opts['print0'] and '\0' or '\n'
60 if opts['print0']:
61 if eol == '\0':
61 eol = '\0'
62 # --print0 implies --print
62 act = False # --print0 implies --print
63 act = False
64 force = bool(opts['force'])
65
66 def error(msg):
67 if abort_on_err:
68 raise util.Abort(msg)
69 else:
70 ui.warn(_('warning: %s\n') % msg)
71
63
72 def remove(remove_func, name):
64 def remove(remove_func, name):
73 if act:
65 if act:
74 try:
66 try:
75 remove_func(os.path.join(repo.root, name))
67 remove_func(os.path.join(repo.root, name))
76 except OSError, e:
68 except OSError, e:
77 error(_('%s cannot be removed') % name)
69 m = _('%s cannot be removed') % name
70 if opts['abort_on_err']:
71 raise util.Abort(m)
72 ui.warn(_('warning: %s\n') % m)
78 else:
73 else:
79 ui.write('%s%s' % (name, eol))
74 ui.write('%s%s' % (name, eol))
80
75
81 if not force:
82 _check_fs(ui, repo)
83
84 directories = []
76 directories = []
85 files = []
86 match = cmdutil.match(repo, dirs, opts)
77 match = cmdutil.match(repo, dirs, opts)
87 match.dir = directories.append
78 match.dir = directories.append
88 status = repo.status(match=match, ignored=opts['all'], unknown=True)
79 status = repo.status(match=match, ignored=opts['all'], unknown=True)
@@ -99,33 +90,11 b' def purge(ui, repo, *dirs, **opts):'
99 ui.note(_('Removing directory %s\n') % f)
90 ui.note(_('Removing directory %s\n') % f)
100 remove(os.rmdir, f)
91 remove(os.rmdir, f)
101
92
102 def _check_fs(ui, repo):
103 """Abort if there is the chance of having problems with name-mangling fs
104
105 In a name mangling filesystem (e.g. a case insensitive one)
106 dirstate.walk() can yield filenames different from the ones
107 stored in the dirstate. This already confuses the status and
108 add commands, but with purge this may cause data loss.
109
110 To prevent this, this function will abort if there are uncommitted
111 changes.
112 """
113
114 # We can't use (files, match) to do a partial walk here - we wouldn't
115 # notice a modified README file if the user ran "hg purge readme"
116 modified, added, removed, deleted = repo.status()[:4]
117 if modified or added or removed or deleted:
118 if not util.checkcase(repo.path) and not ui.quiet:
119 ui.warn(_("Purging on case-insensitive filesystems is not "
120 "fully supported.\n"))
121 raise util.Abort(_("outstanding uncommitted changes"))
122
123 cmdtable = {
93 cmdtable = {
124 'purge|clean':
94 'purge|clean':
125 (purge,
95 (purge,
126 [('a', 'abort-on-err', None, _('abort if an error occurs')),
96 [('a', 'abort-on-err', None, _('abort if an error occurs')),
127 ('', 'all', None, _('purge ignored files too')),
97 ('', 'all', None, _('purge ignored files too')),
128 ('f', 'force', None, _('purge even when there are uncommitted changes')),
129 ('p', 'print', None, _('print the file names instead of deleting them')),
98 ('p', 'print', None, _('print the file names instead of deleting them')),
130 ('0', 'print0', None, _('end filenames with NUL, for use with xargs'
99 ('0', 'print0', None, _('end filenames with NUL, for use with xargs'
131 ' (implies -p)')),
100 ' (implies -p)')),
@@ -83,23 +83,15 b' touch untracked_file'
83 rm r1
83 rm r1
84 # hide error messages to avoid changing the output when the text changes
84 # hide error messages to avoid changing the output when the text changes
85 hg purge -p 2> /dev/null
85 hg purge -p 2> /dev/null
86 if [ $? -ne 0 ]; then
86 hg st
87 echo "refused to run"
87
88 fi
88 hg purge -p
89 if [ -f untracked_file ]; then
90 echo "untracked_file still around"
91 fi
92 hg purge -p --force
93 hg purge -v 2> /dev/null
89 hg purge -v 2> /dev/null
94 if [ $? -ne 0 ]; then
90 hg st
95 echo "refused to run"
91
96 fi
92 hg purge -v
97 if [ -f untracked_file ]; then
98 echo "untracked_file still around"
99 fi
100 hg purge -v --force
101 hg revert --all --quiet
93 hg revert --all --quiet
102 ls
94 hg st -a
103
95
104 echo '% tracked file in ignored directory (issue621)'
96 echo '% tracked file in ignored directory (issue621)'
105 echo directory >> .hgignore
97 echo directory >> .hgignore
@@ -51,14 +51,12 b' Removing file ignored'
51 directory
51 directory
52 r1
52 r1
53 % abort with missing files until we support name mangling filesystems
53 % abort with missing files until we support name mangling filesystems
54 refused to run
55 untracked_file still around
56 untracked_file
54 untracked_file
57 refused to run
55 ! r1
58 untracked_file still around
56 ? untracked_file
57 untracked_file
59 Removing file untracked_file
58 Removing file untracked_file
60 directory
59 ! r1
61 r1
62 % tracked file in ignored directory (issue621)
60 % tracked file in ignored directory (issue621)
63 untracked_file
61 untracked_file
64 Removing file untracked_file
62 Removing file untracked_file
General Comments 0
You need to be logged in to leave comments. Login now