Mercurial > hg-stable
changeset 14395:dc961471efde
mq: check patch name is valid before reading imported file
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Fri, 20 May 2011 21:19:33 +0300 |
parents | 5b98d7416a32 |
children | 170747a3e139 |
files | hgext/mq.py tests/test-mq-qimport.t |
diffstat | 2 files changed, 12 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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]