[PATCH V5] forget: add --dry-run mode
Sushil khanchi
sushilkhanchi97 at gmail.com
Wed Mar 14 05:06:11 UTC 2018
# HG changeset patch
# User Sushil khanchi <sushilkhanchi97 at gmail.com>
# Date 1520665399 -19800
# Sat Mar 10 12:33:19 2018 +0530
# Node ID bd9d29c4c929d0495e874d0c35d96cae29f5ff72
# Parent 4c71a26a4009d88590c9ae3d64a5912fd556d82e
forget: add --dry-run mode
diff -r 4c71a26a4009 -r bd9d29c4c929 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py Sun Mar 04 21:16:36 2018 -0500
+++ b/mercurial/cmdutil.py Sat Mar 10 12:33:19 2018 +0530
@@ -1996,7 +1996,7 @@
for subpath in ctx.substate:
ctx.sub(subpath).addwebdirpath(serverpath, webconf)
-def forget(ui, repo, match, prefix, explicitonly):
+def forget(ui, repo, match, prefix, explicitonly, dryrun):
join = lambda f: os.path.join(prefix, f)
bad = []
badfn = lambda x, y: bad.append(x) or match.bad(x, y)
@@ -2012,7 +2012,7 @@
sub = wctx.sub(subpath)
try:
submatch = matchmod.subdirmatcher(subpath, match)
- subbad, subforgot = sub.forget(submatch, prefix)
+ subbad, subforgot = sub.forget(submatch, prefix, dryrun=dryrun)
bad.extend([subpath + '/' + f for f in subbad])
forgot.extend([subpath + '/' + f for f in subforgot])
except error.LookupError:
@@ -2039,9 +2039,10 @@
if ui.verbose or not match.exact(f):
ui.status(_('removing %s\n') % match.rel(f))
- rejected = wctx.forget(forget, prefix)
- bad.extend(f for f in rejected if f in match.files())
- forgot.extend(f for f in forget if f not in rejected)
+ if not dryrun:
+ rejected = wctx.forget(forget, prefix)
+ bad.extend(f for f in rejected if f in match.files())
+ forgot.extend(f for f in forget if f not in rejected)
return bad, forgot
def files(ui, ctx, m, fm, fmt, subrepos):
diff -r 4c71a26a4009 -r bd9d29c4c929 mercurial/commands.py
--- a/mercurial/commands.py Sun Mar 04 21:16:36 2018 -0500
+++ b/mercurial/commands.py Sat Mar 10 12:33:19 2018 +0530
@@ -2036,7 +2036,10 @@
with ui.formatter('files', opts) as fm:
return cmdutil.files(ui, ctx, m, fm, fmt, opts.get('subrepos'))
- at command('^forget', walkopts, _('[OPTION]... FILE...'), inferrepo=True)
+ at command(
+ '^forget',
+ walkopts + dryrunopts,
+ _('[OPTION]... FILE...'), inferrepo=True)
def forget(ui, repo, *pats, **opts):
"""forget the specified files on the next commit
@@ -2071,7 +2074,9 @@
raise error.Abort(_('no files specified'))
m = scmutil.match(repo[None], pats, opts)
- rejected = cmdutil.forget(ui, repo, m, prefix="", explicitonly=False)[0]
+ dryrun = opts.get(r'dry_run')
+ rejected = cmdutil.forget(ui, repo, m, prefix="",
+ explicitonly=False, dryrun=dryrun)[0]
return rejected and 1 or 0
@command(
diff -r 4c71a26a4009 -r bd9d29c4c929 mercurial/subrepo.py
--- a/mercurial/subrepo.py Sun Mar 04 21:16:36 2018 -0500
+++ b/mercurial/subrepo.py Sat Mar 10 12:33:19 2018 +0530
@@ -811,9 +811,10 @@
return ctx.walk(match)
@annotatesubrepoerror
- def forget(self, match, prefix):
+ def forget(self, match, prefix, dryrun):
return cmdutil.forget(self.ui, self._repo, match,
- self.wvfs.reljoin(prefix, self._path), True)
+ self.wvfs.reljoin(prefix, self._path),
+ True, dryrun=dryrun)
@annotatesubrepoerror
def removefiles(self, matcher, prefix, after, force, subrepos, warnings):
diff -r 4c71a26a4009 -r bd9d29c4c929 tests/test-commit.t
--- a/tests/test-commit.t Sun Mar 04 21:16:36 2018 -0500
+++ b/tests/test-commit.t Sat Mar 10 12:33:19 2018 +0530
@@ -832,3 +832,18 @@
$ cd ..
+test --dry-run mode in forget
+
+ $ hg init testdir_forget
+ $ cd testdir_forget
+ $ echo foo > foo
+ $ hg add foo
+ $ hg commit -m "foo"
+ $ hg forget foo --dry-run -v
+ removing foo
+ $ hg diff
+ $ hg forget not_exist -n
+ not_exist: $ENOENT$
+ [1]
+
+ $ cd ..
More information about the Mercurial-devel
mailing list