--- a/hgext/mq.py Sat May 21 15:01:28 2011 -0500
+++ b/hgext/mq.py Fri May 20 21:19:33 2011 +0300
@@ -1829,11 +1829,14 @@
patchname = filename
else:
+ if filename == '-' and not patchname:
+ raise util.Abort(_('need --name to import a patch from -'))
+ elif not patchname:
+ patchname = normname(os.path.basename(filename))
+ self.check_reserved_name(patchname)
+ checkfile(patchname)
try:
if filename == '-':
- if not patchname:
- raise util.Abort(
- _('need --name to import a patch from -'))
text = sys.stdin.read()
else:
fp = url.open(self.ui, filename)
@@ -1841,10 +1844,6 @@
fp.close()
except (OSError, IOError):
raise util.Abort(_("unable to read file %s") % filename)
- if not patchname:
- patchname = normname(os.path.basename(filename))
- self.check_reserved_name(patchname)
- checkfile(patchname)
patchf = self.opener(patchname, "w")
patchf.write(text)
patchf.close()
--- a/tests/test-mq-qimport.t Sat May 21 15:01:28 2011 -0500
+++ b/tests/test-mq-qimport.t Fri May 20 21:19:33 2011 +0300
@@ -202,3 +202,9 @@
$ hg qser
this-name-is-better
url.diff
+
+qimport with bad name, should abort before reading file
+
+ $ hg qimport non-existant-file --name .hg
+ abort: patch name cannot begin with ".hg"
+ [255]