if head is None:
head = "head"
+ try:
+ Script.verify_rev_id(revid)
+ except revision.RevisionError as err:
+ compat.raise_from_cause(util.CommandError(err.args[0]))
+
with self._catch_revision_errors(multiple_heads=(
"Multiple heads are present; please specify the head "
"revision on which the new revision should be based, "
message=message if message is not None else ("empty message"),
**kw
)
- script = Script._from_path(self, path)
+ try:
+ script = Script._from_path(self, path)
+ except revision.RevisionError as err:
+ compat.raise_from_cause(util.CommandError(err.args[0]))
if branch_labels and not script.branch_labels:
raise util.CommandError(
"Version %s specified branch_labels %s, however the "
from ..util import compat
_relative_destination = re.compile(r'(?:(.+?)@)?(\w+)?((?:\+|-)\d+)')
+_revision_illegal_chars = ['@', '-']
class RevisionError(Exception):
"""Optional string/tuple of symbolic names to apply to this
revision's branch"""
+ @classmethod
+ def verify_rev_id(cls, revision):
+ illegal_chars = set(revision).intersection(_revision_illegal_chars)
+ if illegal_chars:
+ raise RevisionError(
+ "Character(s) '%s' not allowed in revision identifier '%s'" % (
+ ", ".join(sorted(illegal_chars)),
+ revision
+ )
+ )
+
def __init__(
self, revision, down_revision,
dependencies=None, branch_labels=None):
+ self.verify_rev_id(revision)
self.revision = revision
self.down_revision = tuple_rev_as_scalar(down_revision)
self.dependencies = tuple_rev_as_scalar(dependencies)
--- /dev/null
+.. change::
+ :tags: bug, commands
+ :tickets: 441
+
+ A :class:`.CommandError` is raised if the "--rev-id" passed to the
+ :func:`.revision` command contains dashes or at-signs, as this interferes
+ with the command notation used to locate revisions.
\ No newline at end of file
self.cfg, message="some message", head=self.b
)
+ def test_illegal_revision_chars(self):
+ assert_raises_message(
+ util.CommandError,
+ r"Character\(s\) '-' not allowed in "
+ "revision identifier 'no-dashes'",
+ command.revision,
+ self.cfg, message="some message", rev_id="no-dashes"
+ )
+
+ assert not os.path.exists(
+ os.path.join(
+ self.env.dir, "versions", "no-dashes_some_message.py"))
+
+ assert_raises_message(
+ util.CommandError,
+ r"Character\(s\) '@' not allowed in "
+ "revision identifier 'no@atsigns'",
+ command.revision,
+ self.cfg, message="some message", rev_id="no@atsigns"
+ )
+
+ assert_raises_message(
+ util.CommandError,
+ r"Character\(s\) '-, @' not allowed in revision "
+ "identifier 'no@atsigns-ordashes'",
+ command.revision,
+ self.cfg, message="some message", rev_id="no@atsigns-ordashes"
+ )
+
def test_create_script_branches(self):
rev = command.revision(
self.cfg, message="some message", branch_label="foobar")