mercurial/merge.py
changeset 46366 135056e8b5a8
parent 46361 dfca84970da8
child 46367 57370e7deb7b
equal deleted inserted replaced
46365:63dfaca9087f 46366:135056e8b5a8
  2322     ignored=False,
  2322     ignored=False,
  2323     removeemptydirs=True,
  2323     removeemptydirs=True,
  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 
  2330     ``matcher`` is a matcher configured to scan the working directory -
  2331     ``matcher`` is a matcher configured to scan the working directory -
  2331     potentially a subset.
  2332     potentially a subset.
  2341     ``abortonerror`` causes an exception to be raised if an error occurs
  2342     ``abortonerror`` causes an exception to be raised if an error occurs
  2342     deleting a file or directory.
  2343     deleting a file or directory.
  2343 
  2344 
  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.
       
  2347 
       
  2348     ``confirm`` ask confirmation before actually removing anything.
  2346 
  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     """
  2350 
  2353 
  2369             directories = []
  2372             directories = []
  2370             matcher.traversedir = directories.append
  2373             matcher.traversedir = directories.append
  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:
  2377                     repo.ui.note(_(b'removing file %s\n') % f)
  2399                     repo.ui.note(_(b'removing file %s\n') % f)
  2378                     remove(repo.wvfs.unlink, f)
  2400                     remove(repo.wvfs.unlink, f)