[PATCH V2] remove: add dry-run functionality
Sushil khanchi
sushilkhanchi97 at gmail.com
Thu Mar 22 16:24:00 UTC 2018
# HG changeset patch
# User Sushil khanchi <sushilkhanchi97 at gmail.com>
# Date 1521655571 -19800
# Wed Mar 21 23:36:11 2018 +0530
# Node ID 9f9650a25f12b4e2472c3d315e51c8df41948e24
# Parent b6a4881cec1937a8d9cd2e9bbbdf5ca31cfa73dd
remove: add dry-run functionality
diff -r b6a4881cec19 -r 9f9650a25f12 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py Sun Mar 18 15:32:49 2018 -0400
+++ b/mercurial/cmdutil.py Wed Mar 21 23:36:11 2018 +0530
@@ -2076,7 +2076,7 @@
return ret
-def remove(ui, repo, m, prefix, after, force, subrepos, warnings=None):
+def remove(ui, repo, m, prefix, after, force, subrepos, dryrun, warnings=None):
join = lambda f: os.path.join(prefix, f)
ret = 0
s = repo.status(match=m, clean=True)
@@ -2101,7 +2101,7 @@
sub = wctx.sub(subpath)
try:
if sub.removefiles(submatch, prefix, after, force, subrepos,
- warnings):
+ dryrun, warnings):
ret = 1
except error.LookupError:
warnings.append(_("skipping missing subrepository: %s\n")
@@ -2181,13 +2181,14 @@
ui.status(_('removing %s\n') % m.rel(f))
ui.progress(_('deleting'), None)
- with repo.wlock():
- if not after:
- for f in list:
- if f in added:
- continue # we never unlink added files on remove
- repo.wvfs.unlinkpath(f, ignoremissing=True)
- repo[None].forget(list)
+ if not dryrun:
+ with repo.wlock():
+ if not after:
+ for f in list:
+ if f in added:
+ continue # we never unlink added files on remove
+ repo.wvfs.unlinkpath(f, ignoremissing=True)
+ repo[None].forget(list)
if warn:
for warning in warnings:
diff -r b6a4881cec19 -r 9f9650a25f12 mercurial/commands.py
--- a/mercurial/commands.py Sun Mar 18 15:32:49 2018 -0400
+++ b/mercurial/commands.py Wed Mar 21 23:36:11 2018 +0530
@@ -4207,7 +4207,7 @@
[('A', 'after', None, _('record delete for missing files')),
('f', 'force', None,
_('forget added files, delete modified files')),
- ] + subrepoopts + walkopts,
+ ] + subrepoopts + walkopts + dryrunopts,
_('[OPTION]... FILE...'),
inferrepo=True)
def remove(ui, repo, *pats, **opts):
@@ -4251,12 +4251,14 @@
opts = pycompat.byteskwargs(opts)
after, force = opts.get('after'), opts.get('force')
+ dryrun = opts.get('dry_run')
if not pats and not after:
raise error.Abort(_('no files specified'))
m = scmutil.match(repo[None], pats, opts)
subrepos = opts.get('subrepos')
- return cmdutil.remove(ui, repo, m, "", after, force, subrepos)
+ return cmdutil.remove(ui, repo, m, "", after, force, subrepos,
+ dryrun=dryrun)
@command('rename|move|mv',
[('A', 'after', None, _('record a rename that has already occurred')),
diff -r b6a4881cec19 -r 9f9650a25f12 mercurial/subrepo.py
--- a/mercurial/subrepo.py Sun Mar 18 15:32:49 2018 -0400
+++ b/mercurial/subrepo.py Wed Mar 21 23:36:11 2018 +0530
@@ -351,7 +351,8 @@
def forget(self, match, prefix, dryrun):
return ([], [])
- def removefiles(self, matcher, prefix, after, force, subrepos, warnings):
+ def removefiles(self, matcher, prefix, after, force, subrepos,
+ dryrun, warnings):
"""remove the matched files from the subrepository and the filesystem,
possibly by force and/or after the file has been removed from the
filesystem. Return 0 on success, 1 on any warning.
@@ -817,10 +818,11 @@
True, dryrun=dryrun)
@annotatesubrepoerror
- def removefiles(self, matcher, prefix, after, force, subrepos, warnings):
+ def removefiles(self, matcher, prefix, after, force, subrepos,
+ dryrun, warnings):
return cmdutil.remove(self.ui, self._repo, matcher,
self.wvfs.reljoin(prefix, self._path),
- after, force, subrepos)
+ after, force, subrepos, dryrun)
@annotatesubrepoerror
def revert(self, substate, *pats, **opts):
diff -r b6a4881cec19 -r 9f9650a25f12 tests/test-completion.t
--- a/tests/test-completion.t Sun Mar 18 15:32:49 2018 -0400
+++ b/tests/test-completion.t Wed Mar 21 23:36:11 2018 +0530
@@ -238,7 +238,7 @@
merge: force, rev, preview, abort, tool
pull: update, force, rev, bookmark, branch, ssh, remotecmd, insecure
push: force, rev, bookmark, branch, new-branch, pushvars, ssh, remotecmd, insecure
- remove: after, force, subrepos, include, exclude
+ remove: after, force, subrepos, include, exclude, dry-run
serve: accesslog, daemon, daemon-postexec, errorlog, port, address, prefix, name, web-conf, webdir-conf, pid-file, stdio, cmdserver, templates, style, ipv6, certificate, subrepos
status: all, modified, added, removed, deleted, clean, unknown, ignored, no-status, terse, copies, print0, rev, change, include, exclude, subrepos, template
summary: remote
diff -r b6a4881cec19 -r 9f9650a25f12 tests/test-remove.t
--- a/tests/test-remove.t Sun Mar 18 15:32:49 2018 -0400
+++ b/tests/test-remove.t Wed Mar 21 23:36:11 2018 +0530
@@ -505,3 +505,20 @@
deleting [===========================================>] 1/1\r (no-eol) (esc)
\r (no-eol) (esc)
[1]
+
+test dry-run for remove
+
+ $ hg init testdryrun
+ $ cd testdryrun
+ $ echo a>a
+ $ hg ci -qAm1
+ $ hg remove a -nv
+ \r (no-eol) (esc)
+ deleting [===========================================>] 1/1\r (no-eol) (esc)
+ \r (no-eol) (esc)
+ \r (no-eol) (esc)
+ deleting [===========================================>] 1/1\r (no-eol) (esc)
+ \r (no-eol) (esc)
+ removing a
+ $ hg diff
+ $ cd ..
More information about the Mercurial-devel
mailing list