Commit 8dc168c8 authored by liscju's avatar liscju

revert: makes interactive mode ask to forget added files (issue4936)

Before this patch revert interactive mode unconditionally forgets
added files. This patch fixes this by asking user if he wants
to forget added file. If user doesn't want to forget given file,
it is added to matcher_opts exclude list, to not reviewing it
later with other modified files.
parent e60e13a86529
......@@ -3130,13 +3130,26 @@ def _performrevert(repo, parents, ctx, actions, interactive=False):
"""
parent, p2 = parents
node = ctx.node()
excluded_files = []
matcher_opts = {"exclude": excluded_files}
def checkout(f):
fc = ctx[f]
repo.wwrite(f, fc.data(), fc.flags())
audit_path = pathutil.pathauditor(repo.root)
for f in actions['forget'][0]:
repo.dirstate.drop(f)
if interactive:
choice = \
repo.ui.promptchoice(
_("forget added file %s (yn)?$$ &Yes $$ &No")
% f)
if choice == 0:
repo.dirstate.drop(f)
else:
excluded_files.append(repo.wjoin(f))
else:
repo.dirstate.drop(f)
for f in actions['remove'][0]:
audit_path(f)
try:
......@@ -3162,7 +3175,7 @@ def _performrevert(repo, parents, ctx, actions, interactive=False):
if interactive:
# Prompt the user for changes to revert
torevert = [repo.wjoin(f) for f in actions['revert'][0]]
m = scmutil.match(ctx, torevert, {})
m = scmutil.match(ctx, torevert, matcher_opts)
diffopts = patch.difffeatureopts(repo.ui, whitespace=True)
diffopts.nodates = True
diffopts.git = True
......
......@@ -15,6 +15,7 @@ Revert interactive tests
> interactive = true
> [extensions]
> record =
> purge =
> EOF
......@@ -377,3 +378,26 @@ Check the experimental config to invert the selection:
5
d
+lastline
$ hg update -C .
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg purge
$ touch newfile
$ hg add newfile
$ hg status
A newfile
$ hg revert -i <<EOF
> n
> EOF
forgetting newfile
forget added file newfile (yn)? n
$ hg status
A newfile
$ hg revert -i <<EOF
> y
> EOF
forgetting newfile
forget added file newfile (yn)? y
$ hg status
? newfile
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment