changeset 50091:a8d71a6ba205

tag: move the prohibition of tagging the `null` rev up to the `wdir()` check It makes sense to do these together, and avoid another revision lookup.
author Matt Harbison <matt_harbison@yahoo.com>
date Tue, 14 Feb 2023 15:45:26 -0500
parents a3c856e2ea2f
children ce60c8d4ac87
files mercurial/commands.py
diffstat 1 files changed, 4 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Fri Feb 17 17:04:41 2023 +0100
+++ b/mercurial/commands.py	Tue Feb 14 15:45:26 2023 -0500
@@ -13,6 +13,7 @@
 from .i18n import _
 from .node import (
     hex,
+    nullid,
     nullrev,
     short,
     wdirrev,
@@ -7500,8 +7501,11 @@
                 )
         node = logcmdutil.revsingle(repo, rev_).node()
 
+        # don't allow tagging the null rev or the working directory
         if node is None:
             raise error.InputError(_(b"cannot tag working directory"))
+        elif not opts.get(b'remove') and node == nullid:
+            raise error.InputError(_(b"cannot tag null revision"))
 
         if not message:
             # we don't translate commit messages
@@ -7522,13 +7526,6 @@
             editform=editform, **pycompat.strkwargs(opts)
         )
 
-        # don't allow tagging the null rev
-        if (
-            not opts.get(b'remove')
-            and logcmdutil.revsingle(repo, rev_).rev() == nullrev
-        ):
-            raise error.InputError(_(b"cannot tag null revision"))
-
         tagsmod.tag(
             repo,
             names,