revert: add prompt before undeleting a file in -i (issue6008)
authorTaapas Agrawal <taapas2897@gmail.com>
Sun, 03 Feb 2019 01:02:24 +0530
changeset 41522 d783c937aa53
parent 41521 bad59bbd9bec
child 41523 3ef8bec91465
revert: add prompt before undeleting a file in -i (issue6008) This adds a prompt that asks whether or not a removed file is to be undeleted in `hg revert -i`. Differential Revision: https://phab.mercurial-scm.org/D5803
mercurial/cmdutil.py
tests/test-revert-interactive.t
--- a/mercurial/cmdutil.py	Sat Feb 02 13:16:46 2019 -0800
+++ b/mercurial/cmdutil.py	Sun Feb 03 01:02:24 2019 +0530
@@ -3194,9 +3194,19 @@
     if node == parent and p2 == nullid:
         normal = repo.dirstate.normal
     for f in actions['undelete'][0]:
-        prntstatusmsg('undelete', f)
-        checkout(f)
-        normal(f)
+        if interactive:
+            choice = repo.ui.promptchoice(
+                _("add back removed file %s (Yn)?$$ &Yes $$ &No") % f)
+            if choice == 0:
+                prntstatusmsg('undelete', f)
+                checkout(f)
+                normal(f)
+            else:
+                excluded_files.append(f)
+        else:
+            prntstatusmsg('undelete', f)
+            checkout(f)
+            normal(f)
 
     copied = copies.pathcopies(repo[parent], ctx)
 
--- a/tests/test-revert-interactive.t	Sat Feb 02 13:16:46 2019 -0800
+++ b/tests/test-revert-interactive.t	Sun Feb 03 01:02:24 2019 +0530
@@ -424,3 +424,24 @@
   b: no such file in rev b40d1912accf
 
   $ cd ..
+
+Prompt before undeleting file(issue6008)
+  $ hg init repo
+  $ cd repo
+  $ echo a > a
+  $ hg ci -qAm a
+  $ hg rm a
+  $ hg revert -i<<EOF
+  > y
+  > EOF
+  add back removed file a (Yn)? y
+  undeleting a
+  $ ls
+  a
+  $ hg rm a
+  $ hg revert -i<<EOF
+  > n
+  > EOF
+  add back removed file a (Yn)? n
+  $ ls
+  $ cd ..