Patchwork D9819: purge: also deal with directory with --confirm

login
register
mail settings
Submitter phabricator
Date Jan. 18, 2021, 9:26 a.m.
Message ID <differential-rev-PHID-DREV-5hbwoxtukvusxxp2jg54-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48130/
State Superseded
Headers show

Comments

phabricator - Jan. 18, 2021, 9:26 a.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9819

AFFECTED FILES
  mercurial/merge.py
  tests/test-purge.t

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-purge.t b/tests/test-purge.t
--- a/tests/test-purge.t
+++ b/tests/test-purge.t
@@ -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
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -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'))