D2934: forget: add --confirm option
khanchi97 (Sushil khanchi)
phabricator at mercurial-scm.org
Mon Mar 26 07:14:10 EDT 2018
khanchi97 updated this revision to Diff 7285.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D2934?vs=7254&id=7285
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,58 @@
[1]
$ cd ..
+
+test --confirm option in forget
+
+ $ hg init forgetconfirm
+ $ cd forgetconfirm
+ $ echo foo > foo
+ $ hg commit -qAm "foo"
+ $ echo bar > bar
+ $ hg commit -qAm "bar"
+ $ hg forget foo --dry-run --confirm
+ abort: can't specify --dry-run and --confirm
+ [255]
+
+ $ hg forget foo --config ui.interactive=True --confirm << EOF
+ > ?
+ > n
+ > EOF
+ forget foo [Ynsa?] ?
+ y - yes, forget this file
+ n - no, skip this file
+ s - skip remaining files
+ a - include all remaining files
+ ? - ? (display help)
+ forget foo [Ynsa?] n
+
+ $ hg forget foo bar --config ui.interactive=True --confirm << EOF
+ > y
+ > n
+ > EOF
+ forget bar [Ynsa?] y
+ forget foo [Ynsa?] n
+ removing bar
+ $ hg status
+ R bar
+ $ hg up -qC .
+
+ $ hg forget foo bar --config ui.interactive=True --confirm << EOF
+ > s
+ > EOF
+ forget bar [Ynsa?] s
+ $ hg st
+ $ hg up -qC .
+
+ $ hg forget foo bar --config ui.interactive=True --confirm << EOF
+ > a
+ > EOF
+ forget bar [Ynsa?] a
+ removing bar
+ removing foo
+ $ hg status
+ R bar
+ R foo
+ $ hg up -qC .
+
+ $ 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,35 @@
% match.rel(f))
bad.append(f)
+ if confirm:
+ responses = _('[Ynsa?]'
+ '$$ &Yes, forget this file'
+ '$$ &No, skip this file'
+ '$$ &Skip remaining files'
+ '$$ Include &all remaining files'
+ '$$ &? (display help)')
+ for filename in forget[:]:
+ r = ui.promptchoice(_('forget %s %s') % (filename, responses))
+ if r == 4: # ?
+ while r == 4:
+ for c, t in ui.extractchoices(responses)[1]:
+ ui.write('%s - %s\n' % (c, encoding.lower(t)))
+ r = ui.promptchoice(_('forget %s %s') % (filename,
+ responses))
+ if r == 0: # yes
+ continue
+ elif r == 1: # no
+ forget.remove(filename)
+ elif r == 2: # Skip
+ fnindex = forget.index(filename)
+ del forget[fnindex:]
+ break
+ elif r == 3: # All
+ break
+
+
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: mharbison72, yuja, pulkit, av6, mercurial-devel
More information about the Mercurial-devel
mailing list