Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.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 | 41c03b7592ed |
children | dc4d0c7b7d94 |
comparison
equal
deleted
inserted
replaced
23288:2b9bc7963504 | 23289:ae5d0a22ee7e |
---|---|
5123 working directory, not even if option --force is specified. | 5123 working directory, not even if option --force is specified. |
5124 | 5124 |
5125 Returns 0 on success, 1 if any warnings encountered. | 5125 Returns 0 on success, 1 if any warnings encountered. |
5126 """ | 5126 """ |
5127 | 5127 |
5128 ret = 0 | |
5129 after, force = opts.get('after'), opts.get('force') | 5128 after, force = opts.get('after'), opts.get('force') |
5130 if not pats and not after: | 5129 if not pats and not after: |
5131 raise util.Abort(_('no files specified')) | 5130 raise util.Abort(_('no files specified')) |
5132 | 5131 |
5133 m = scmutil.match(repo[None], pats, opts) | 5132 m = scmutil.match(repo[None], pats, opts) |
5134 s = repo.status(match=m, clean=True) | 5133 return cmdutil.remove(ui, repo, m, after, force) |
5135 modified, added, deleted, clean = s[0], s[1], s[3], s[6] | |
5136 | |
5137 # warn about failure to delete explicit files/dirs | |
5138 wctx = repo[None] | |
5139 for f in m.files(): | |
5140 if f in repo.dirstate or f in wctx.dirs(): | |
5141 continue | |
5142 if os.path.exists(m.rel(f)): | |
5143 if os.path.isdir(m.rel(f)): | |
5144 ui.warn(_('not removing %s: no tracked files\n') % m.rel(f)) | |
5145 else: | |
5146 ui.warn(_('not removing %s: file is untracked\n') % m.rel(f)) | |
5147 # missing files will generate a warning elsewhere | |
5148 ret = 1 | |
5149 | |
5150 if force: | |
5151 list = modified + deleted + clean + added | |
5152 elif after: | |
5153 list = deleted | |
5154 for f in modified + added + clean: | |
5155 ui.warn(_('not removing %s: file still exists\n') % m.rel(f)) | |
5156 ret = 1 | |
5157 else: | |
5158 list = deleted + clean | |
5159 for f in modified: | |
5160 ui.warn(_('not removing %s: file is modified (use -f' | |
5161 ' to force removal)\n') % m.rel(f)) | |
5162 ret = 1 | |
5163 for f in added: | |
5164 ui.warn(_('not removing %s: file has been marked for add' | |
5165 ' (use forget to undo)\n') % m.rel(f)) | |
5166 ret = 1 | |
5167 | |
5168 for f in sorted(list): | |
5169 if ui.verbose or not m.exact(f): | |
5170 ui.status(_('removing %s\n') % m.rel(f)) | |
5171 | |
5172 wlock = repo.wlock() | |
5173 try: | |
5174 if not after: | |
5175 for f in list: | |
5176 if f in added: | |
5177 continue # we never unlink added files on remove | |
5178 util.unlinkpath(repo.wjoin(f), ignoremissing=True) | |
5179 repo[None].forget(list) | |
5180 finally: | |
5181 wlock.release() | |
5182 | |
5183 return ret | |
5184 | 5134 |
5185 @command('rename|move|mv', | 5135 @command('rename|move|mv', |
5186 [('A', 'after', None, _('record a rename that has already occurred')), | 5136 [('A', 'after', None, _('record a rename that has already occurred')), |
5187 ('f', 'force', None, _('forcibly copy over an existing managed file')), | 5137 ('f', 'force', None, _('forcibly copy over an existing managed file')), |
5188 ] + walkopts + dryrunopts, | 5138 ] + walkopts + dryrunopts, |