changeset 46367:57370e7deb7b

purge: also deal with directory with --confirm Getting the exact number is simple (you have to project the result of previous deletion to detect super-directory with only about-to-be-deleted content). So we use a vaguer message. Differential Revision: https://phab.mercurial-scm.org/D9819
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 18 Jan 2021 10:24:11 +0100
parents 135056e8b5a8
children bb3a5c0df06b
files mercurial/merge.py tests/test-purge.t
diffstat 2 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/merge.py	Mon Jan 18 10:24:03 2021 +0100
+++ b/mercurial/merge.py	Mon Jan 18 10:24:11 2021 +0100
@@ -2386,9 +2386,19 @@
             elif nb_ignored:
                 msg = _(b"permanently delete %d ignored files?")
                 msg %= nb_ignored
-            else:
-                # XXX we might be missing directory there
-                return res
+            elif removeemptydirs:
+                dir_count = 0
+                for f in directories:
+                    if matcher(f) and not repo.wvfs.listdir(f):
+                        dir_count += 1
+                if dir_count:
+                    msg = _(
+                        b"permanently delete at least %d empty directories?"
+                    )
+                    msg %= dir_count
+                else:
+                    # XXX we might be missing directory there
+                    return res
             msg += b" (yN)$$ &Yes $$ &No"
             if repo.ui.promptchoice(msg, default=1) == 1:
                 raise error.CanceledError(_(b'removal cancelled'))
--- a/tests/test-purge.t	Mon Jan 18 10:24:03 2021 +0100
+++ b/tests/test-purge.t	Mon Jan 18 10:24:11 2021 +0100
@@ -23,6 +23,10 @@
   $ mkdir empty_dir
   $ hg purge -p -v
   empty_dir
+  $ hg purge --confirm
+  permanently delete at least 1 empty directories? (yN) n
+  abort: removal cancelled
+  [250]
   $ hg purge -v
   removing directory empty_dir
   $ ls -A