tag: disallow tagging the working directory stable
authorMatt Harbison <matt_harbison@yahoo.com>
Tue, 14 Feb 2023 11:56:02 -0500
branchstable
changeset 50087 4fc6b423fa97
parent 50078 983e2db18d67
child 50089 5fb2546d0df1
child 50090 a3c856e2ea2f
tag: disallow tagging the working directory It's kinda silly, but a clear error message is better than a stacktrace about subscripting `None` when trying to generate the default commit message. I'm surprised that `.revsingle(..).node()` returns None instead of `nodemod.wdirid`, but now there's a test to catch if this changes.
mercurial/commands.py
tests/test-tag.t
--- a/mercurial/commands.py	Thu Feb 16 20:33:14 2023 +0100
+++ b/mercurial/commands.py	Tue Feb 14 11:56:02 2023 -0500
@@ -7472,6 +7472,9 @@
                 )
         node = logcmdutil.revsingle(repo, rev_).node()
 
+        if node is None:
+            raise error.InputError(_(b"cannot tag working directory"))
+
         if not message:
             # we don't translate commit messages
             message = b'Added tag %s for changeset %s' % (
--- a/tests/test-tag.t	Thu Feb 16 20:33:14 2023 +0100
+++ b/tests/test-tag.t	Tue Feb 14 11:56:02 2023 -0500
@@ -412,6 +412,10 @@
   abort: cannot tag null revision
   [10]
 
+  $ hg tag -R empty -r "wdir()" -f wdirtag
+  abort: cannot tag working directory
+  [10]
+
 issue5539: pruned tags do not appear in .hgtags
 
   $ cat >> $HGRCPATH << EOF