# HG changeset patch # User Matt Harbison # Date 2023-02-14 16:56:02 # Node ID 4fc6b423fa973fe33d718d16815dd6b14669a475 # Parent 983e2db18d67e8cd27323616ba195e5bd36553df 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. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -7472,6 +7472,9 @@ def tag(ui, repo, name1, *names, **opts) ) 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' % ( diff --git a/tests/test-tag.t b/tests/test-tag.t --- a/tests/test-tag.t +++ b/tests/test-tag.t @@ -412,6 +412,10 @@ tagging on null rev 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