mercurial/cmdutil.py
changeset 28607 a88959ae5938
parent 28601 cd10171d6c71
child 28608 62e73d42bd14
equal deleted inserted replaced
28606:8cc51c5a9365 28607:a88959ae5938
  2402                 ui.status(_("skipping missing subrepository: %s\n")
  2402                 ui.status(_("skipping missing subrepository: %s\n")
  2403                                % m.abs(subpath))
  2403                                % m.abs(subpath))
  2404 
  2404 
  2405     return ret
  2405     return ret
  2406 
  2406 
  2407 def remove(ui, repo, m, prefix, after, force, subrepos):
  2407 def remove(ui, repo, m, prefix, after, force, subrepos, warnings=None):
  2408     join = lambda f: os.path.join(prefix, f)
  2408     join = lambda f: os.path.join(prefix, f)
  2409     ret = 0
  2409     ret = 0
  2410     s = repo.status(match=m, clean=True)
  2410     s = repo.status(match=m, clean=True)
  2411     modified, added, deleted, clean = s[0], s[1], s[3], s[6]
  2411     modified, added, deleted, clean = s[0], s[1], s[3], s[6]
  2412 
  2412 
  2413     wctx = repo[None]
  2413     wctx = repo[None]
       
  2414 
       
  2415     if warnings is None:
       
  2416         warnings = []
       
  2417         warn = True
       
  2418     else:
       
  2419         warn = False
  2414 
  2420 
  2415     for subpath in sorted(wctx.substate):
  2421     for subpath in sorted(wctx.substate):
  2416         def matchessubrepo(matcher, subpath):
  2422         def matchessubrepo(matcher, subpath):
  2417             if matcher.exact(subpath):
  2423             if matcher.exact(subpath):
  2418                 return True
  2424                 return True
  2423 
  2429 
  2424         if subrepos or matchessubrepo(m, subpath):
  2430         if subrepos or matchessubrepo(m, subpath):
  2425             sub = wctx.sub(subpath)
  2431             sub = wctx.sub(subpath)
  2426             try:
  2432             try:
  2427                 submatch = matchmod.subdirmatcher(subpath, m)
  2433                 submatch = matchmod.subdirmatcher(subpath, m)
  2428                 if sub.removefiles(submatch, prefix, after, force, subrepos):
  2434                 if sub.removefiles(submatch, prefix, after, force, subrepos,
       
  2435                                    warnings):
  2429                     ret = 1
  2436                     ret = 1
  2430             except error.LookupError:
  2437             except error.LookupError:
  2431                 ui.status(_("skipping missing subrepository: %s\n")
  2438                 warnings.append(_("skipping missing subrepository: %s\n")
  2432                                % join(subpath))
  2439                                % join(subpath))
  2433 
  2440 
  2434     # warn about failure to delete explicit files/dirs
  2441     # warn about failure to delete explicit files/dirs
  2435     deleteddirs = util.dirs(deleted)
  2442     deleteddirs = util.dirs(deleted)
  2436     for f in m.files():
  2443     for f in m.files():
  2444         if f in repo.dirstate or isdir or f == '.' or insubrepo():
  2451         if f in repo.dirstate or isdir or f == '.' or insubrepo():
  2445             continue
  2452             continue
  2446 
  2453 
  2447         if repo.wvfs.exists(f):
  2454         if repo.wvfs.exists(f):
  2448             if repo.wvfs.isdir(f):
  2455             if repo.wvfs.isdir(f):
  2449                 ui.warn(_('not removing %s: no tracked files\n')
  2456                 warnings.append(_('not removing %s: no tracked files\n')
  2450                         % m.rel(f))
  2457                         % m.rel(f))
  2451             else:
  2458             else:
  2452                 ui.warn(_('not removing %s: file is untracked\n')
  2459                 warnings.append(_('not removing %s: file is untracked\n')
  2453                         % m.rel(f))
  2460                         % m.rel(f))
  2454         # missing files will generate a warning elsewhere
  2461         # missing files will generate a warning elsewhere
  2455         ret = 1
  2462         ret = 1
  2456 
  2463 
  2457     if force:
  2464     if force:
  2458         list = modified + deleted + clean + added
  2465         list = modified + deleted + clean + added
  2459     elif after:
  2466     elif after:
  2460         list = deleted
  2467         list = deleted
  2461         for f in modified + added + clean:
  2468         for f in modified + added + clean:
  2462             ui.warn(_('not removing %s: file still exists\n') % m.rel(f))
  2469             warnings.append(_('not removing %s: file still exists\n') % m.rel(f))
  2463             ret = 1
  2470             ret = 1
  2464     else:
  2471     else:
  2465         list = deleted + clean
  2472         list = deleted + clean
  2466         for f in modified:
  2473         for f in modified:
  2467             ui.warn(_('not removing %s: file is modified (use -f'
  2474             warnings.append(_('not removing %s: file is modified (use -f'
  2468                       ' to force removal)\n') % m.rel(f))
  2475                       ' to force removal)\n') % m.rel(f))
  2469             ret = 1
  2476             ret = 1
  2470         for f in added:
  2477         for f in added:
  2471             ui.warn(_('not removing %s: file has been marked for add'
  2478             warnings.append(_('not removing %s: file has been marked for add'
  2472                       ' (use forget to undo)\n') % m.rel(f))
  2479                       ' (use forget to undo)\n') % m.rel(f))
  2473             ret = 1
  2480             ret = 1
  2474 
  2481 
  2475     for f in sorted(list):
  2482     for f in sorted(list):
  2476         if ui.verbose or not m.exact(f):
  2483         if ui.verbose or not m.exact(f):
  2481             for f in list:
  2488             for f in list:
  2482                 if f in added:
  2489                 if f in added:
  2483                     continue # we never unlink added files on remove
  2490                     continue # we never unlink added files on remove
  2484                 util.unlinkpath(repo.wjoin(f), ignoremissing=True)
  2491                 util.unlinkpath(repo.wjoin(f), ignoremissing=True)
  2485         repo[None].forget(list)
  2492         repo[None].forget(list)
       
  2493 
       
  2494     if warn:
       
  2495         for warning in warnings:
       
  2496             ui.warn(warning)
  2486 
  2497 
  2487     return ret
  2498     return ret
  2488 
  2499 
  2489 def cat(ui, repo, ctx, matcher, prefix, **opts):
  2500 def cat(ui, repo, ctx, matcher, prefix, **opts):
  2490     err = 1
  2501     err = 1