class CommandContext:
"Consime a revision specification or range from an argument list"
- def __init__(self, cmd, args):
+ def __init__(self, cmd, args, require_empty=False):
if not os.path.exists(repodir):
croak("repository subdirectory %s does not exist" % repodir)
self.start = self.end = None
self.end = self.start
except ValueError:
croak("malformed revision spec: %s" % revspec)
+ if require_empty and not self.is_empty():
+ croak("%s doesn't take a revision spec" % legend)
if not self.args:
try:
masters = os.listdir(repodir)
os.mkdir(repodir)
except OSError:
croak(" %s creation failed, check directory permissions." % repodir)
- ctx = CommandContext("add", args)
- if not ctx.is_empty():
- croak("add doesn't take a revision spec")
+ ctx = CommandContext("add", args, require_empty=True)
for arg in ctx.args:
if not os.path.exists(arg):
croak("I see no '%s' here." % arg)
croak("repository subdirectory %s does not exist" % repodir)
args = list(args)
comment = get_comment("commit", args)
- ctx = CommandContext("commit", args)
- if not ctx.is_empty():
- croak("commit doesn't take a revision spec")
+ ctx = CommandContext("commit", args, require_empty=True)
for arg in ctx.args:
if not os.path.exists(arg):
croak("I see no '%s' here." % arg)
tag_helper(args, "branch", backend.delete_branch, backend.set_branch)
def filecmd(legend, hook, args):
- ctx = CommandContext(legend, args)
- if not ctx.is_empty():
- croak("%s doesn't take a revision spec" % legend)
- elif len(args) != 2:
+ ctx = CommandContext(legend, args, require_empty=True)
+ if len(args) != 2:
croak("%s requires exactly two arguments" % legend)
(source, target) = args
if not os.path.exists(source):
def release_method(*args):
"Release locks."
- ctx = CommandContext("release", args)
- if not ctx.is_empty():
- croak("release doesn't take a revision spec")
+ ctx = CommandContext("release", args, require_empty=True)
for arg in ctx.args:
if not os.path.exists(arg):
croak("I see no '%s' here." % arg)