##// END OF EJS Templates
purge: add a --confirm option...
marmoute -
r47078:135056e8 default
parent child Browse files
Show More
@@ -61,6 +61,7 b" testedwith = b'ships-with-hg-core'"
61 b' (implies -p/--print)'
61 b' (implies -p/--print)'
62 ),
62 ),
63 ),
63 ),
64 (b'', b'confirm', None, _(b'ask before permanently deleting files')),
64 ]
65 ]
65 + cmdutil.walkopts,
66 + cmdutil.walkopts,
66 _(b'hg purge [OPTION]... [DIR]...'),
67 _(b'hg purge [OPTION]... [DIR]...'),
@@ -113,6 +114,7 b' def purge(ui, repo, *dirs, **opts):'
113
114
114 removefiles = opts.get(b'files')
115 removefiles = opts.get(b'files')
115 removedirs = opts.get(b'dirs')
116 removedirs = opts.get(b'dirs')
117 confirm = opts.get(b'confirm')
116
118
117 if not removefiles and not removedirs:
119 if not removefiles and not removedirs:
118 removefiles = True
120 removefiles = True
@@ -129,6 +131,7 b' def purge(ui, repo, *dirs, **opts):'
129 removefiles=removefiles,
131 removefiles=removefiles,
130 abortonerror=opts.get(b'abort_on_err'),
132 abortonerror=opts.get(b'abort_on_err'),
131 noop=not act,
133 noop=not act,
134 confirm=confirm,
132 )
135 )
133
136
134 for path in paths:
137 for path in paths:
@@ -2324,6 +2324,7 b' def purge('
2324 removefiles=True,
2324 removefiles=True,
2325 abortonerror=False,
2325 abortonerror=False,
2326 noop=False,
2326 noop=False,
2327 confirm=False,
2327 ):
2328 ):
2328 """Purge the working directory of untracked files.
2329 """Purge the working directory of untracked files.
2329
2330
@@ -2344,6 +2345,8 b' def purge('
2344 ``noop`` controls whether to actually remove files. If not defined, actions
2345 ``noop`` controls whether to actually remove files. If not defined, actions
2345 will be taken.
2346 will be taken.
2346
2347
2348 ``confirm`` ask confirmation before actually removing anything.
2349
2347 Returns an iterable of relative paths in the working directory that were
2350 Returns an iterable of relative paths in the working directory that were
2348 or would be removed.
2351 or would be removed.
2349 """
2352 """
@@ -2371,6 +2374,25 b' def purge('
2371
2374
2372 status = repo.status(match=matcher, ignored=ignored, unknown=unknown)
2375 status = repo.status(match=matcher, ignored=ignored, unknown=unknown)
2373
2376
2377 if confirm:
2378 nb_ignored = len(status.ignored)
2379 nb_unkown = len(status.unknown)
2380 if nb_unkown and nb_ignored:
2381 msg = _(b"permanently delete %d unkown and %d ignored files?")
2382 msg %= (nb_unkown, nb_ignored)
2383 elif nb_unkown:
2384 msg = _(b"permanently delete %d unkown files?")
2385 msg %= nb_unkown
2386 elif nb_ignored:
2387 msg = _(b"permanently delete %d ignored files?")
2388 msg %= nb_ignored
2389 else:
2390 # XXX we might be missing directory there
2391 return res
2392 msg += b" (yN)$$ &Yes $$ &No"
2393 if repo.ui.promptchoice(msg, default=1) == 1:
2394 raise error.CanceledError(_(b'removal cancelled'))
2395
2374 if removefiles:
2396 if removefiles:
2375 for f in sorted(status.unknown + status.ignored):
2397 for f in sorted(status.unknown + status.ignored):
2376 if not noop:
2398 if not noop:
@@ -62,6 +62,10 b' delete an untracked file'
62 $ hg purge -p
62 $ hg purge -p
63 untracked_file
63 untracked_file
64 untracked_file_readonly
64 untracked_file_readonly
65 $ hg purge --confirm
66 permanently delete 2 unkown files? (yN) n
67 abort: removal cancelled
68 [250]
65 $ hg purge -v
69 $ hg purge -v
66 removing file untracked_file
70 removing file untracked_file
67 removing file untracked_file_readonly
71 removing file untracked_file_readonly
@@ -121,6 +125,10 b' delete only part of the tree'
121 $ cd directory
125 $ cd directory
122 $ hg purge -p ../untracked_directory
126 $ hg purge -p ../untracked_directory
123 untracked_directory/nested_directory
127 untracked_directory/nested_directory
128 $ hg purge --confirm
129 permanently delete 1 unkown files? (yN) n
130 abort: removal cancelled
131 [250]
124 $ hg purge -v ../untracked_directory
132 $ hg purge -v ../untracked_directory
125 removing directory untracked_directory/nested_directory
133 removing directory untracked_directory/nested_directory
126 removing directory untracked_directory
134 removing directory untracked_directory
@@ -138,6 +146,7 b' skip ignored files if -i or --all not sp'
138
146
139 $ touch ignored
147 $ touch ignored
140 $ hg purge -p
148 $ hg purge -p
149 $ hg purge --confirm
141 $ hg purge -v
150 $ hg purge -v
142 $ touch untracked_file
151 $ touch untracked_file
143 $ ls
152 $ ls
@@ -147,6 +156,10 b' skip ignored files if -i or --all not sp'
147 untracked_file
156 untracked_file
148 $ hg purge -p -i
157 $ hg purge -p -i
149 ignored
158 ignored
159 $ hg purge --confirm -i
160 permanently delete 1 ignored files? (yN) n
161 abort: removal cancelled
162 [250]
150 $ hg purge -v -i
163 $ hg purge -v -i
151 removing file ignored
164 removing file ignored
152 $ ls -A
165 $ ls -A
@@ -159,6 +172,10 b' skip ignored files if -i or --all not sp'
159 $ hg purge -p --all
172 $ hg purge -p --all
160 ignored
173 ignored
161 untracked_file
174 untracked_file
175 $ hg purge --confirm --all
176 permanently delete 1 unkown and 1 ignored files? (yN) n
177 abort: removal cancelled
178 [250]
162 $ hg purge -v --all
179 $ hg purge -v --all
163 removing file ignored
180 removing file ignored
164 removing file untracked_file
181 removing file untracked_file
General Comments 0
You need to be logged in to leave comments. Login now