Show More
@@ -61,6 +61,7 b" testedwith = b'ships-with-hg-core'" | |||
|
61 | 61 | b' (implies -p/--print)' |
|
62 | 62 | ), |
|
63 | 63 | ), |
|
64 | (b'', b'confirm', None, _(b'ask before permanently deleting files')), | |
|
64 | 65 | ] |
|
65 | 66 | + cmdutil.walkopts, |
|
66 | 67 | _(b'hg purge [OPTION]... [DIR]...'), |
@@ -113,6 +114,7 b' def purge(ui, repo, *dirs, **opts):' | |||
|
113 | 114 | |
|
114 | 115 | removefiles = opts.get(b'files') |
|
115 | 116 | removedirs = opts.get(b'dirs') |
|
117 | confirm = opts.get(b'confirm') | |
|
116 | 118 | |
|
117 | 119 | if not removefiles and not removedirs: |
|
118 | 120 | removefiles = True |
@@ -129,6 +131,7 b' def purge(ui, repo, *dirs, **opts):' | |||
|
129 | 131 | removefiles=removefiles, |
|
130 | 132 | abortonerror=opts.get(b'abort_on_err'), |
|
131 | 133 | noop=not act, |
|
134 | confirm=confirm, | |
|
132 | 135 | ) |
|
133 | 136 | |
|
134 | 137 | for path in paths: |
@@ -2324,6 +2324,7 b' def purge(' | |||
|
2324 | 2324 | removefiles=True, |
|
2325 | 2325 | abortonerror=False, |
|
2326 | 2326 | noop=False, |
|
2327 | confirm=False, | |
|
2327 | 2328 | ): |
|
2328 | 2329 | """Purge the working directory of untracked files. |
|
2329 | 2330 | |
@@ -2344,6 +2345,8 b' def purge(' | |||
|
2344 | 2345 | ``noop`` controls whether to actually remove files. If not defined, actions |
|
2345 | 2346 | will be taken. |
|
2346 | 2347 | |
|
2348 | ``confirm`` ask confirmation before actually removing anything. | |
|
2349 | ||
|
2347 | 2350 | Returns an iterable of relative paths in the working directory that were |
|
2348 | 2351 | or would be removed. |
|
2349 | 2352 | """ |
@@ -2371,6 +2374,25 b' def purge(' | |||
|
2371 | 2374 | |
|
2372 | 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 | 2396 | if removefiles: |
|
2375 | 2397 | for f in sorted(status.unknown + status.ignored): |
|
2376 | 2398 | if not noop: |
@@ -62,6 +62,10 b' delete an untracked file' | |||
|
62 | 62 | $ hg purge -p |
|
63 | 63 | untracked_file |
|
64 | 64 | untracked_file_readonly |
|
65 | $ hg purge --confirm | |
|
66 | permanently delete 2 unkown files? (yN) n | |
|
67 | abort: removal cancelled | |
|
68 | [250] | |
|
65 | 69 | $ hg purge -v |
|
66 | 70 | removing file untracked_file |
|
67 | 71 | removing file untracked_file_readonly |
@@ -121,6 +125,10 b' delete only part of the tree' | |||
|
121 | 125 | $ cd directory |
|
122 | 126 | $ hg purge -p ../untracked_directory |
|
123 | 127 | untracked_directory/nested_directory |
|
128 | $ hg purge --confirm | |
|
129 | permanently delete 1 unkown files? (yN) n | |
|
130 | abort: removal cancelled | |
|
131 | [250] | |
|
124 | 132 | $ hg purge -v ../untracked_directory |
|
125 | 133 | removing directory untracked_directory/nested_directory |
|
126 | 134 | removing directory untracked_directory |
@@ -138,6 +146,7 b' skip ignored files if -i or --all not sp' | |||
|
138 | 146 | |
|
139 | 147 | $ touch ignored |
|
140 | 148 | $ hg purge -p |
|
149 | $ hg purge --confirm | |
|
141 | 150 | $ hg purge -v |
|
142 | 151 | $ touch untracked_file |
|
143 | 152 | $ ls |
@@ -147,6 +156,10 b' skip ignored files if -i or --all not sp' | |||
|
147 | 156 | untracked_file |
|
148 | 157 | $ hg purge -p -i |
|
149 | 158 | ignored |
|
159 | $ hg purge --confirm -i | |
|
160 | permanently delete 1 ignored files? (yN) n | |
|
161 | abort: removal cancelled | |
|
162 | [250] | |
|
150 | 163 | $ hg purge -v -i |
|
151 | 164 | removing file ignored |
|
152 | 165 | $ ls -A |
@@ -159,6 +172,10 b' skip ignored files if -i or --all not sp' | |||
|
159 | 172 | $ hg purge -p --all |
|
160 | 173 | ignored |
|
161 | 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 | 179 | $ hg purge -v --all |
|
163 | 180 | removing file ignored |
|
164 | 181 | removing file untracked_file |
General Comments 0
You need to be logged in to leave comments.
Login now