# HG changeset patch # User Alexis S. L. Carvalho # Date 1202079826 7200 # Node ID ca2af0c81c9adca727c95d4d7786fe8883a129db # Parent dcda0c90125c8408bef9005812d7c4a2ce5ea901 mq: don't allow patches with some reserved names The current list of reserved names includes only mq control files. Also, reserve names starting with ".hg" (to avoid troubles with e.g. .hgignore and .hgtags), and with ".mq" (to allow future extensions). This should fix issue841. diff -r dcda0c90125c -r ca2af0c81c9a hgext/mq.py --- a/hgext/mq.py Sun Feb 03 21:03:46 2008 -0200 +++ b/hgext/mq.py Sun Feb 03 21:03:46 2008 -0200 @@ -600,9 +600,17 @@ 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 @@ 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 @@ 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 @@ 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 -r dcda0c90125c -r ca2af0c81c9a tests/test-mq --- a/tests/test-mq Sun Feb 03 21:03:46 2008 -0200 +++ b/tests/test-mq Sun Feb 03 21:03:46 2008 -0200 @@ -42,6 +42,12 @@ 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 -r dcda0c90125c -r ca2af0c81c9a tests/test-mq.out --- a/tests/test-mq.out Sun Feb 03 21:03:46 2008 -0200 +++ b/tests/test-mq.out Sun Feb 03 21:03:46 2008 -0200 @@ -59,6 +59,11 @@ % 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