Mercurial > public > mercurial-scm > hg-stable
diff mercurial/cmdutil.py @ 23289:ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
This will allow access to the reusable parts from subrepos, similar to add(),
forget(), etc.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sun, 09 Nov 2014 12:31:34 -0500 |
parents | 10697f29af2b |
children | 4165cfd67519 |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Tue Nov 11 20:08:19 2014 -0800 +++ b/mercurial/cmdutil.py Sun Nov 09 12:31:34 2014 -0500 @@ -2052,6 +2052,59 @@ forgot.extend(forget) return bad, forgot +def remove(ui, repo, m, after, force): + ret = 0 + s = repo.status(match=m, clean=True) + modified, added, deleted, clean = s[0], s[1], s[3], s[6] + + # warn about failure to delete explicit files/dirs + wctx = repo[None] + for f in m.files(): + if f in repo.dirstate or f in wctx.dirs(): + continue + if os.path.exists(m.rel(f)): + if os.path.isdir(m.rel(f)): + ui.warn(_('not removing %s: no tracked files\n') % m.rel(f)) + else: + ui.warn(_('not removing %s: file is untracked\n') % m.rel(f)) + # missing files will generate a warning elsewhere + ret = 1 + + if force: + list = modified + deleted + clean + added + elif after: + list = deleted + for f in modified + added + clean: + ui.warn(_('not removing %s: file still exists\n') % m.rel(f)) + ret = 1 + else: + list = deleted + clean + for f in modified: + ui.warn(_('not removing %s: file is modified (use -f' + ' to force removal)\n') % m.rel(f)) + ret = 1 + for f in added: + ui.warn(_('not removing %s: file has been marked for add' + ' (use forget to undo)\n') % m.rel(f)) + ret = 1 + + for f in sorted(list): + if ui.verbose or not m.exact(f): + ui.status(_('removing %s\n') % m.rel(f)) + + wlock = repo.wlock() + try: + if not after: + for f in list: + if f in added: + continue # we never unlink added files on remove + util.unlinkpath(repo.wjoin(f), ignoremissing=True) + repo[None].forget(list) + finally: + wlock.release() + + return ret + def cat(ui, repo, ctx, matcher, prefix, **opts): err = 1