purge: prevent a silly crash with --confirm --files stable 6.1.4
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 14 Jun 2022 11:26:18 +0200
branchstable
changeset 48894 0cc5f74ff7f0
parent 48893 6cd249556e20
child 48895 d4db76996492
purge: prevent a silly crash with --confirm --files if --files is passed, there was no directory to checks and `msg` was undefined. This is now fixed and tested.
mercurial/merge.py
tests/test-purge.t
--- a/mercurial/merge.py	Wed Jun 08 19:15:58 2022 +0200
+++ b/mercurial/merge.py	Tue Jun 14 11:26:18 2022 +0200
@@ -2442,6 +2442,7 @@
         status = repo.status(match=matcher, ignored=ignored, unknown=unknown)
 
         if confirm:
+            msg = None
             nb_ignored = len(status.ignored)
             nb_unknown = len(status.unknown)
             if nb_unknown and nb_ignored:
@@ -2463,12 +2464,12 @@
                         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'))
+            if msg is None:
+                return res
+            else:
+                msg += b" (yN)$$ &Yes $$ &No"
+                if repo.ui.promptchoice(msg, default=1) == 1:
+                    raise error.CanceledError(_(b'removal cancelled'))
 
         if removefiles:
             for f in sorted(status.unknown + status.ignored):
--- a/tests/test-purge.t	Wed Jun 08 19:15:58 2022 +0200
+++ b/tests/test-purge.t	Tue Jun 14 11:26:18 2022 +0200
@@ -350,4 +350,9 @@
   .hg
   .hgignore
 
+Test some --confirm case that ended crashing
+
+  $ hg purge --confirm
+  $ hg purge --confirm --all --files
+
   $ cd ..