Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 50144: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 | 774ed116dd7c |
comparison
equal
deleted
inserted
replaced
50143:a3c856e2ea2f | 50144:a8d71a6ba205 |
---|---|
11 import sys | 11 import sys |
12 | 12 |
13 from .i18n import _ | 13 from .i18n import _ |
14 from .node import ( | 14 from .node import ( |
15 hex, | 15 hex, |
16 nullid, | |
16 nullrev, | 17 nullrev, |
17 short, | 18 short, |
18 wdirrev, | 19 wdirrev, |
19 ) | 20 ) |
20 from .pycompat import open | 21 from .pycompat import open |
7498 b'(use -f to force)' | 7499 b'(use -f to force)' |
7499 ) | 7500 ) |
7500 ) | 7501 ) |
7501 node = logcmdutil.revsingle(repo, rev_).node() | 7502 node = logcmdutil.revsingle(repo, rev_).node() |
7502 | 7503 |
7504 # don't allow tagging the null rev or the working directory | |
7503 if node is None: | 7505 if node is None: |
7504 raise error.InputError(_(b"cannot tag working directory")) | 7506 raise error.InputError(_(b"cannot tag working directory")) |
7507 elif not opts.get(b'remove') and node == nullid: | |
7508 raise error.InputError(_(b"cannot tag null revision")) | |
7505 | 7509 |
7506 if not message: | 7510 if not message: |
7507 # we don't translate commit messages | 7511 # we don't translate commit messages |
7508 message = b'Added tag %s for changeset %s' % ( | 7512 message = b'Added tag %s for changeset %s' % ( |
7509 b', '.join(names), | 7513 b', '.join(names), |
7519 else: | 7523 else: |
7520 editform = b'tag.add' | 7524 editform = b'tag.add' |
7521 editor = cmdutil.getcommiteditor( | 7525 editor = cmdutil.getcommiteditor( |
7522 editform=editform, **pycompat.strkwargs(opts) | 7526 editform=editform, **pycompat.strkwargs(opts) |
7523 ) | 7527 ) |
7524 | |
7525 # don't allow tagging the null rev | |
7526 if ( | |
7527 not opts.get(b'remove') | |
7528 and logcmdutil.revsingle(repo, rev_).rev() == nullrev | |
7529 ): | |
7530 raise error.InputError(_(b"cannot tag null revision")) | |
7531 | 7528 |
7532 tagsmod.tag( | 7529 tagsmod.tag( |
7533 repo, | 7530 repo, |
7534 names, | 7531 names, |
7535 node, | 7532 node, |