revert: prompt before removing files in interactive mode
authorDenis Laxalde <denis.laxalde@logilab.fr>
Fri, 25 Nov 2016 09:10:30 +0100
changeset 30541 66b162fa3ffa
parent 30540 841092fd6b85
child 30542 40fe96fc7cd2
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).
mercurial/cmdutil.py
tests/test-revert-interactive.t
--- a/mercurial/cmdutil.py	Fri Nov 25 09:09:31 2016 +0100
+++ b/mercurial/cmdutil.py	Fri Nov 25 09:10:30 2016 +0100
@@ -3167,6 +3167,13 @@
         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:
@@ -3180,11 +3187,15 @@
             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)
--- a/tests/test-revert-interactive.t	Fri Nov 25 09:09:31 2016 +0100
+++ b/tests/test-revert-interactive.t	Fri Nov 25 09:10:30 2016 +0100
@@ -46,6 +46,7 @@
   > y
   > y
   > y
+  > y
   > n
   > n
   > EOF
@@ -53,6 +54,7 @@
   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 @@
   $ 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 @@
   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 @@
   $ hg st
   M f
   M folder1/g
-  R folder1/i
   $ hg revert --interactive f << EOF
   > y
   > y
@@ -290,7 +293,6 @@
   $ hg st
   M f
   M folder1/g
-  R folder1/i
   ? f.orig
   $ cat f
   a
@@ -307,7 +309,7 @@
   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