D2934: forget: add --confirm option
khanchi97 (Sushil khanchi)
phabricator at mercurial-scm.org
Thu Mar 22 15:50:39 EDT 2018
khanchi97 updated this revision to Diff 7254.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D2934?vs=7252&id=7254
REVISION DETAIL
https://phab.mercurial-scm.org/D2934
AFFECTED FILES
mercurial/cmdutil.py
mercurial/commands.py
tests/test-add.t
tests/test-completion.t
CHANGE DETAILS
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -232,7 +232,7 @@
commit: addremove, close-branch, amend, secret, edit, interactive, include, exclude, message, logfile, date, user, subrepos
diff: rev, change, text, git, binary, nodates, noprefix, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, ignore-space-at-eol, unified, stat, root, include, exclude, subrepos
export: output, switch-parent, rev, text, git, binary, nodates
- forget: include, exclude, dry-run
+ forget: include, exclude, dry-run, confirm
init: ssh, remotecmd, insecure
log: follow, follow-first, date, copies, keyword, rev, line-range, removed, only-merges, user, only-branch, branch, prune, patch, git, limit, no-merges, stat, graph, style, template, include, exclude
merge: force, rev, preview, abort, tool
diff --git a/tests/test-add.t b/tests/test-add.t
--- a/tests/test-add.t
+++ b/tests/test-add.t
@@ -272,3 +272,30 @@
[1]
$ cd ..
+
+test --confirm option in forget
+
+ $ hg init forgetconfirm
+ $ cd forgetconfirm
+ $ echo foo > foo
+ $ hg commit -qAm "foo"
+ $ hg forget foo --dry-run --confirm
+ abort: can't specify --dry-run and --confirm
+ [255]
+ $ hg forget foo --confirm << EOF
+ > y
+ > EOF
+ forget foo (yn)? y
+ removing foo
+ $ hg status
+ R foo
+ $ hg up -qC .
+ $ hg forget foo --confirm << EOF
+ > n
+ > EOF
+ forget foo (yn)? y
+ removing foo
+ $ hg status
+ R foo
+
+ $ cd ..
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -108,6 +108,7 @@
]
dryrunopts = cmdutil.dryrunopts
+confirmopts = cmdutil.confirmopts
remoteopts = cmdutil.remoteopts
walkopts = cmdutil.walkopts
commitopts = cmdutil.commitopts
@@ -2039,7 +2040,7 @@
@command(
'^forget',
- walkopts + dryrunopts,
+ walkopts + dryrunopts + confirmopts,
_('[OPTION]... FILE...'), inferrepo=True)
def forget(ui, repo, *pats, **opts):
"""forget the specified files on the next commit
@@ -2075,9 +2076,10 @@
raise error.Abort(_('no files specified'))
m = scmutil.match(repo[None], pats, opts)
- dryrun = opts.get(r'dry_run')
+ dryrun, confirm = opts.get('dry_run'), opts.get('confirm')
rejected = cmdutil.forget(ui, repo, m, prefix="",
- explicitonly=False, dryrun=dryrun)[0]
+ explicitonly=False, dryrun=dryrun,
+ confirm=confirm)[0]
return rejected and 1 or 0
@command(
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -58,6 +58,11 @@
_('do not perform actions, just print output')),
]
+confirmopts = [
+ ('', 'confirm', None,
+ _('ask before applying actions')),
+]
+
remoteopts = [
('e', 'ssh', '',
_('specify ssh command to use'), _('CMD')),
@@ -1997,7 +2002,9 @@
for subpath in ctx.substate:
ctx.sub(subpath).addwebdirpath(serverpath, webconf)
-def forget(ui, repo, match, prefix, explicitonly, dryrun):
+def forget(ui, repo, match, prefix, explicitonly, dryrun, confirm):
+ if dryrun and confirm:
+ raise error.Abort(_("can't specify --dry-run and --confirm"))
join = lambda f: os.path.join(prefix, f)
bad = []
badfn = lambda x, y: bad.append(x) or match.bad(x, y)
@@ -2013,7 +2020,8 @@
sub = wctx.sub(subpath)
try:
submatch = matchmod.subdirmatcher(subpath, match)
- subbad, subforgot = sub.forget(submatch, prefix, dryrun=dryrun)
+ subbad, subforgot = sub.forget(submatch, prefix,
+ dryrun=dryrun, confirm=confirm)
bad.extend([subpath + '/' + f for f in subbad])
forgot.extend([subpath + '/' + f for f in subforgot])
except error.LookupError:
@@ -2036,8 +2044,14 @@
% match.rel(f))
bad.append(f)
+ if confirm:
+ filenames = ' '.join(forget)
+ if ui.promptchoice(_('forget %s (yn)?'
+ '$$ &Yes $$ &No') % filenames):
+ raise error.Abort(_('forget canceled'))
+
for f in forget:
- if ui.verbose or not match.exact(f):
+ if ui.verbose or not match.exact(f) or confirm:
ui.status(_('removing %s\n') % match.rel(f))
if not dryrun:
To: khanchi97, #hg-reviewers, av6, pulkit
Cc: pulkit, av6, mercurial-devel
More information about the Mercurial-devel
mailing list