##// END OF EJS Templates
remove: add dry-run functionality
Sushil khanchi -
r37168:335e19c6 default
parent child Browse files
Show More
@@ -178,7 +178,7 b' def addlargefiles(ui, repo, isaddremove,'
178 added = [f for f in lfnames if f not in bad]
178 added = [f for f in lfnames if f not in bad]
179 return added, bad
179 return added, bad
180
180
181 def removelargefiles(ui, repo, isaddremove, matcher, **opts):
181 def removelargefiles(ui, repo, isaddremove, matcher, dryrun, **opts):
182 after = opts.get(r'after')
182 after = opts.get(r'after')
183 m = composelargefilematcher(matcher, repo[None].manifest())
183 m = composelargefilematcher(matcher, repo[None].manifest())
184 try:
184 try:
@@ -223,11 +223,11 b' def removelargefiles(ui, repo, isaddremo'
223 name = m.rel(f)
223 name = m.rel(f)
224 ui.status(_('removing %s\n') % name)
224 ui.status(_('removing %s\n') % name)
225
225
226 if not opts.get(r'dry_run'):
226 if not dryrun:
227 if not after:
227 if not after:
228 repo.wvfs.unlinkpath(f, ignoremissing=True)
228 repo.wvfs.unlinkpath(f, ignoremissing=True)
229
229
230 if opts.get(r'dry_run'):
230 if dryrun:
231 return result
231 return result
232
232
233 remove = [lfutil.standin(f) for f in remove]
233 remove = [lfutil.standin(f) for f in remove]
@@ -271,10 +271,12 b' def cmdutiladd(orig, ui, repo, matcher, '
271 bad.extend(f for f in lbad)
271 bad.extend(f for f in lbad)
272 return bad
272 return bad
273
273
274 def cmdutilremove(orig, ui, repo, matcher, prefix, after, force, subrepos):
274 def cmdutilremove(orig, ui, repo, matcher, prefix, after, force, subrepos,
275 dryrun):
275 normalmatcher = composenormalfilematcher(matcher, repo[None].manifest())
276 normalmatcher = composenormalfilematcher(matcher, repo[None].manifest())
276 result = orig(ui, repo, normalmatcher, prefix, after, force, subrepos)
277 result = orig(ui, repo, normalmatcher, prefix, after, force, subrepos,
277 return removelargefiles(ui, repo, False, matcher, after=after,
278 dryrun)
279 return removelargefiles(ui, repo, False, matcher, dryrun, after=after,
278 force=force) or result
280 force=force) or result
279
281
280 def overridestatusfn(orig, repo, rev2, **opts):
282 def overridestatusfn(orig, repo, rev2, **opts):
@@ -1238,7 +1240,8 b' def scmutiladdremove(orig, repo, matcher'
1238 matchfn = m.matchfn
1240 matchfn = m.matchfn
1239 m.matchfn = lambda f: f in s.deleted and matchfn(f)
1241 m.matchfn = lambda f: f in s.deleted and matchfn(f)
1240
1242
1241 removelargefiles(repo.ui, repo, True, m, **pycompat.strkwargs(opts))
1243 removelargefiles(repo.ui, repo, True, m, opts.get('dry_run'),
1244 **pycompat.strkwargs(opts))
1242 # Call into the normal add code, and any files that *should* be added as
1245 # Call into the normal add code, and any files that *should* be added as
1243 # largefiles will be
1246 # largefiles will be
1244 added, bad = addlargefiles(repo.ui, repo, True, matcher,
1247 added, bad = addlargefiles(repo.ui, repo, True, matcher,
@@ -2083,7 +2083,7 b' def files(ui, ctx, m, fm, fmt, subrepos)'
2083
2083
2084 return ret
2084 return ret
2085
2085
2086 def remove(ui, repo, m, prefix, after, force, subrepos, warnings=None):
2086 def remove(ui, repo, m, prefix, after, force, subrepos, dryrun, warnings=None):
2087 join = lambda f: os.path.join(prefix, f)
2087 join = lambda f: os.path.join(prefix, f)
2088 ret = 0
2088 ret = 0
2089 s = repo.status(match=m, clean=True)
2089 s = repo.status(match=m, clean=True)
@@ -2108,7 +2108,7 b' def remove(ui, repo, m, prefix, after, f'
2108 sub = wctx.sub(subpath)
2108 sub = wctx.sub(subpath)
2109 try:
2109 try:
2110 if sub.removefiles(submatch, prefix, after, force, subrepos,
2110 if sub.removefiles(submatch, prefix, after, force, subrepos,
2111 warnings):
2111 dryrun, warnings):
2112 ret = 1
2112 ret = 1
2113 except error.LookupError:
2113 except error.LookupError:
2114 warnings.append(_("skipping missing subrepository: %s\n")
2114 warnings.append(_("skipping missing subrepository: %s\n")
@@ -2188,13 +2188,14 b' def remove(ui, repo, m, prefix, after, f'
2188 ui.status(_('removing %s\n') % m.rel(f))
2188 ui.status(_('removing %s\n') % m.rel(f))
2189 ui.progress(_('deleting'), None)
2189 ui.progress(_('deleting'), None)
2190
2190
2191 with repo.wlock():
2191 if not dryrun:
2192 if not after:
2192 with repo.wlock():
2193 for f in list:
2193 if not after:
2194 if f in added:
2194 for f in list:
2195 continue # we never unlink added files on remove
2195 if f in added:
2196 repo.wvfs.unlinkpath(f, ignoremissing=True)
2196 continue # we never unlink added files on remove
2197 repo[None].forget(list)
2197 repo.wvfs.unlinkpath(f, ignoremissing=True)
2198 repo[None].forget(list)
2198
2199
2199 if warn:
2200 if warn:
2200 for warning in warnings:
2201 for warning in warnings:
@@ -4213,7 +4213,7 b' def recover(ui, repo):'
4213 [('A', 'after', None, _('record delete for missing files')),
4213 [('A', 'after', None, _('record delete for missing files')),
4214 ('f', 'force', None,
4214 ('f', 'force', None,
4215 _('forget added files, delete modified files')),
4215 _('forget added files, delete modified files')),
4216 ] + subrepoopts + walkopts,
4216 ] + subrepoopts + walkopts + dryrunopts,
4217 _('[OPTION]... FILE...'),
4217 _('[OPTION]... FILE...'),
4218 inferrepo=True)
4218 inferrepo=True)
4219 def remove(ui, repo, *pats, **opts):
4219 def remove(ui, repo, *pats, **opts):
@@ -4257,12 +4257,14 b' def remove(ui, repo, *pats, **opts):'
4257
4257
4258 opts = pycompat.byteskwargs(opts)
4258 opts = pycompat.byteskwargs(opts)
4259 after, force = opts.get('after'), opts.get('force')
4259 after, force = opts.get('after'), opts.get('force')
4260 dryrun = opts.get('dry_run')
4260 if not pats and not after:
4261 if not pats and not after:
4261 raise error.Abort(_('no files specified'))
4262 raise error.Abort(_('no files specified'))
4262
4263
4263 m = scmutil.match(repo[None], pats, opts)
4264 m = scmutil.match(repo[None], pats, opts)
4264 subrepos = opts.get('subrepos')
4265 subrepos = opts.get('subrepos')
4265 return cmdutil.remove(ui, repo, m, "", after, force, subrepos)
4266 return cmdutil.remove(ui, repo, m, "", after, force, subrepos,
4267 dryrun=dryrun)
4266
4268
4267 @command('rename|move|mv',
4269 @command('rename|move|mv',
4268 [('A', 'after', None, _('record a rename that has already occurred')),
4270 [('A', 'after', None, _('record a rename that has already occurred')),
@@ -355,7 +355,8 b' class abstractsubrepo(object):'
355 def forget(self, match, prefix, dryrun):
355 def forget(self, match, prefix, dryrun):
356 return ([], [])
356 return ([], [])
357
357
358 def removefiles(self, matcher, prefix, after, force, subrepos, warnings):
358 def removefiles(self, matcher, prefix, after, force, subrepos,
359 dryrun, warnings):
359 """remove the matched files from the subrepository and the filesystem,
360 """remove the matched files from the subrepository and the filesystem,
360 possibly by force and/or after the file has been removed from the
361 possibly by force and/or after the file has been removed from the
361 filesystem. Return 0 on success, 1 on any warning.
362 filesystem. Return 0 on success, 1 on any warning.
@@ -821,10 +822,11 b' class hgsubrepo(abstractsubrepo):'
821 True, dryrun=dryrun)
822 True, dryrun=dryrun)
822
823
823 @annotatesubrepoerror
824 @annotatesubrepoerror
824 def removefiles(self, matcher, prefix, after, force, subrepos, warnings):
825 def removefiles(self, matcher, prefix, after, force, subrepos,
826 dryrun, warnings):
825 return cmdutil.remove(self.ui, self._repo, matcher,
827 return cmdutil.remove(self.ui, self._repo, matcher,
826 self.wvfs.reljoin(prefix, self._path),
828 self.wvfs.reljoin(prefix, self._path),
827 after, force, subrepos)
829 after, force, subrepos, dryrun)
828
830
829 @annotatesubrepoerror
831 @annotatesubrepoerror
830 def revert(self, substate, *pats, **opts):
832 def revert(self, substate, *pats, **opts):
@@ -238,7 +238,7 b' Show all commands + options'
238 merge: force, rev, preview, abort, tool
238 merge: force, rev, preview, abort, tool
239 pull: update, force, rev, bookmark, branch, ssh, remotecmd, insecure
239 pull: update, force, rev, bookmark, branch, ssh, remotecmd, insecure
240 push: force, rev, bookmark, branch, new-branch, pushvars, ssh, remotecmd, insecure
240 push: force, rev, bookmark, branch, new-branch, pushvars, ssh, remotecmd, insecure
241 remove: after, force, subrepos, include, exclude
241 remove: after, force, subrepos, include, exclude, dry-run
242 serve: accesslog, daemon, daemon-postexec, errorlog, port, address, prefix, name, web-conf, webdir-conf, pid-file, stdio, cmdserver, templates, style, ipv6, certificate, subrepos
242 serve: accesslog, daemon, daemon-postexec, errorlog, port, address, prefix, name, web-conf, webdir-conf, pid-file, stdio, cmdserver, templates, style, ipv6, certificate, subrepos
243 status: all, modified, added, removed, deleted, clean, unknown, ignored, no-status, terse, copies, print0, rev, change, include, exclude, subrepos, template
243 status: all, modified, added, removed, deleted, clean, unknown, ignored, no-status, terse, copies, print0, rev, change, include, exclude, subrepos, template
244 summary: remote
244 summary: remote
@@ -2857,6 +2857,9 b' Dish up an empty repo; serve it cold.'
2857 <tr><td>-X</td>
2857 <tr><td>-X</td>
2858 <td>--exclude PATTERN [+]</td>
2858 <td>--exclude PATTERN [+]</td>
2859 <td>exclude names matching the given patterns</td></tr>
2859 <td>exclude names matching the given patterns</td></tr>
2860 <tr><td>-n</td>
2861 <td>--dry-run</td>
2862 <td>do not perform actions, just print output</td></tr>
2860 </table>
2863 </table>
2861 <p>
2864 <p>
2862 global options ([+] can be repeated):
2865 global options ([+] can be repeated):
@@ -505,3 +505,32 b' handling of untracked directories and mi'
505 deleting [===========================================>] 1/1\r (no-eol) (esc)
505 deleting [===========================================>] 1/1\r (no-eol) (esc)
506 \r (no-eol) (esc)
506 \r (no-eol) (esc)
507 [1]
507 [1]
508
509 test dry-run for remove
510
511 $ hg init testdryrun
512 $ cd testdryrun
513 $ echo a>a
514 $ hg ci -qAm1
515 $ hg remove a -nv
516 \r (no-eol) (esc)
517 deleting [===========================================>] 1/1\r (no-eol) (esc)
518 \r (no-eol) (esc)
519 \r (no-eol) (esc)
520 deleting [===========================================>] 1/1\r (no-eol) (esc)
521 \r (no-eol) (esc)
522 removing a
523 $ hg diff
524
525 $ cat >> .hg/hgrc <<EOF
526 > [extensions]
527 > largefiles=
528 > EOF
529 $ echo 'B as largefile' > B
530 $ hg add --large B
531 $ hg ci -m "B"
532 $ hg remove B -nv
533 removing B
534 $ hg st
535
536 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now