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: @@ -2037,9 +2045,14 @@ bad.append(f) 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 confirm: + if ui.promptchoice(_('are you sure you want to forget (yn)?' + '$$ &Yes $$ &No')): + raise error.Abort(_('forget canceled')) + if not dryrun: rejected = wctx.forget(forget, prefix) bad.extend(f for f in rejected if f in match.files()) 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(r'dry_run'), opts.get(r'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/tests/test-add.t b/tests/test-add.t --- a/tests/test-add.t +++ b/tests/test-add.t @@ -272,3 +272,32 @@ [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 -v << EOF + > y + > EOF + removing foo + are you sure you want to forget (yn)? y + $ hg diff + diff -r e63c23eaa88a foo + --- a/foo Thu Jan 01 00:00:00 1970 +0000 + +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 + @@ -1,1 +0,0 @@ + -foo + + $ hg up -qC . + $ hg forget foo --confirm -v << EOF + > n + > EOF + removing foo + are you sure you want to forget (yn)? y + $ cd ..