diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -600,9 +600,17 @@ class queue: raise util.Abort(_("local changes found")) return m, a, r, d + _reserved = ('series', 'status', 'guards') + def check_reserved_name(self, name): + if (name in self._reserved or name.startswith('.hg') + or name.startswith('.mq')): + raise util.Abort(_('"%s" cannot be used as the name of a patch') + % name) + def new(self, repo, patch, *pats, **opts): msg = opts.get('msg') force = opts.get('force') + self.check_reserved_name(patch) if os.path.exists(self.join(patch)): raise util.Abort(_('patch "%s" already exists') % patch) if opts.get('include') or opts.get('exclude') or pats: @@ -1372,6 +1380,7 @@ class queue: if not patchname: patchname = normname('%d.diff' % r) + self.check_reserved_name(patchname) checkseries(patchname) checkfile(patchname) self.full_series.insert(0, patchname) @@ -1394,6 +1403,7 @@ class queue: raise util.Abort(_('-e is incompatible with import from -')) if not patchname: patchname = normname(filename) + self.check_reserved_name(patchname) if not os.path.isfile(self.join(patchname)): raise util.Abort(_("patch %s does not exist") % patchname) else: @@ -1408,6 +1418,7 @@ class queue: raise util.Abort(_("unable to read %s") % patchname) if not patchname: patchname = normname(os.path.basename(filename)) + self.check_reserved_name(patchname) checkfile(patchname) patchf = self.opener(patchname, "w") patchf.write(text) diff --git a/tests/test-mq b/tests/test-mq --- a/tests/test-mq +++ b/tests/test-mq @@ -42,6 +42,12 @@ echo % qinit -c hg --cwd c qinit -c hg -R c/.hg/patches st +echo % qnew should refuse bad patch names +hg -R c qnew series +hg -R c qnew status +hg -R c qnew guards +hg -R c qnew .hgignore + echo % qnew implies add hg -R c qnew test.patch diff --git a/tests/test-mq.out b/tests/test-mq.out --- a/tests/test-mq.out +++ b/tests/test-mq.out @@ -59,6 +59,11 @@ adding b/z % qinit -c A .hgignore A series +% qnew should refuse bad patch names +abort: "series" cannot be used as the name of a patch +abort: "status" cannot be used as the name of a patch +abort: "guards" cannot be used as the name of a patch +abort: ".hgignore" cannot be used as the name of a patch % qnew implies add A .hgignore A series