archive: abort on empty repository. Fixes #624.
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -133,7 +133,10 @@ def archive(ui, repo, dest, **opts):
The default is the basename of the archive, with suffixes removed.
'''
- node = repo.changectx(opts['rev']).node()
+ ctx = repo.changectx(opts['rev'])
+ if not ctx:
+ raise util.Abort(_('repository has no revisions'))
+ node = ctx.node()
dest = cmdutil.make_filename(repo, dest, node)
if os.path.realpath(dest) == repo.root:
raise util.Abort(_('repository root cannot be destination'))
--- a/tests/test-archive
+++ b/tests/test-archive
@@ -67,3 +67,9 @@ hg archive -r 0 -t tar rev-%r.tar
if [ -f rev-0.tar ]; then
echo 'rev-0.tar created'
fi
+
+echo '% empty repo'
+hg init ../empty
+cd ../empty
+hg archive ../test-empty
+exit 0
--- a/tests/test-archive.out
+++ b/tests/test-archive.out
@@ -39,3 +39,5 @@ test-TIP/bar
test-TIP/baz/bletch
test-TIP/foo
rev-0.tar created
+% empty repo
+abort: repository has no revisions