Patchwork [3,of,3] revert: prompt before removing files in interactive mode

login
register
mail settings
Submitter Denis Laxalde
Date Nov. 25, 2016, 8:43 a.m.
Message ID <ea1c62be7e0782d32ddb.1480063383@sh77.tls.logilab.fr>
Download mbox | patch
Permalink /patch/17751/
State Accepted
Headers show

Comments

Denis Laxalde - Nov. 25, 2016, 8:43 a.m.
# HG changeset patch
# User Denis Laxalde <denis.laxalde@logilab.fr>
# Date 1480061430 -3600
#      Fri Nov 25 09:10:30 2016 +0100
# Node ID ea1c62be7e0782d32ddbee782ace3efee7ccdfdd
# Parent  0df7774c49eda9f95f255066cfddae296c13a33a
# EXP-Topic revert/interactive-remove
revert: prompt before removing files in interactive mode

Prior to this change, files to be removed (i.e. files added since the revision
to revert to) were unconditionally removed despite the interactive mode. Now
prompt before actually removing the files, as this is done for other actions
(e.g. forget).
Pierre-Yves David - Nov. 25, 2016, 9:30 a.m.
On 11/25/2016 09:43 AM, Denis Laxalde wrote:
> # HG changeset patch
> # User Denis Laxalde <denis.laxalde@logilab.fr>
> # Date 1480061430 -3600
> #      Fri Nov 25 09:10:30 2016 +0100
> # Node ID ea1c62be7e0782d32ddbee782ace3efee7ccdfdd
> # Parent  0df7774c49eda9f95f255066cfddae296c13a33a
> # EXP-Topic revert/interactive-remove
> revert: prompt before removing files in interactive mode
>
> Prior to this change, files to be removed (i.e. files added since the revision
> to revert to) were unconditionally removed despite the interactive mode. Now
> prompt before actually removing the files, as this is done for other actions
> (e.g. forget).

These are pushed, thanks.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -3252,6 +3252,13 @@  def _performrevert(repo, parents, ctx, a
         fc = ctx[f]
         repo.wwrite(f, fc.data(), fc.flags())
 
+    def doremove(f):
+        try:
+            util.unlinkpath(repo.wjoin(f))
+        except OSError:
+            pass
+        repo.dirstate.remove(f)
+
     audit_path = pathutil.pathauditor(repo.root)
     for f in actions['forget'][0]:
         if interactive:
@@ -3265,11 +3272,15 @@  def _performrevert(repo, parents, ctx, a
             repo.dirstate.drop(f)
     for f in actions['remove'][0]:
         audit_path(f)
-        try:
-            util.unlinkpath(repo.wjoin(f))
-        except OSError:
-            pass
-        repo.dirstate.remove(f)
+        if interactive:
+            choice = repo.ui.promptchoice(
+                _("remove added file %s (Yn)?$$ &Yes $$ &No") % f)
+            if choice == 0:
+                doremove(f)
+            else:
+                excluded_files.append(repo.wjoin(f))
+        else:
+            doremove(f)
     for f in actions['drop'][0]:
         audit_path(f)
         repo.dirstate.remove(f)
diff --git a/tests/test-revert-interactive.t b/tests/test-revert-interactive.t
--- a/tests/test-revert-interactive.t
+++ b/tests/test-revert-interactive.t
@@ -46,6 +46,7 @@  10 run the same test than 8 from within 
   > y
   > y
   > y
+  > y
   > n
   > n
   > EOF
@@ -53,6 +54,7 @@  10 run the same test than 8 from within 
   reverting folder1/g (glob)
   removing folder1/i (glob)
   reverting folder2/h (glob)
+  remove added file folder1/i (Yn)? y
   diff --git a/f b/f
   2 hunks, 2 lines changed
   examine changes to 'f'? [Ynesfdaq?] y
@@ -174,6 +176,7 @@  Test --no-backup
   $ hg update -C 6
   3 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg revert -i -r 2 --all -- << EOF
+  > n
   > y
   > y
   > y
@@ -186,6 +189,7 @@  Test --no-backup
   reverting folder1/g (glob)
   removing folder1/i (glob)
   reverting folder2/h (glob)
+  remove added file folder1/i (Yn)? n
   diff --git a/f b/f
   2 hunks, 2 lines changed
   examine changes to 'f'? [Ynesfdaq?] y
@@ -258,7 +262,6 @@  Test --no-backup
   $ hg st
   M f
   M folder1/g
-  R folder1/i
   $ hg revert --interactive f << EOF
   > y
   > y
@@ -290,7 +293,6 @@  Test --no-backup
   $ hg st
   M f
   M folder1/g
-  R folder1/i
   ? f.orig
   $ cat f
   a
@@ -307,7 +309,7 @@  Test --no-backup
   5
   $ rm f.orig
   $ hg update -C .
-  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
 Check editing files newly added by a revert