--- a/hgext/narrow/narrowcommands.py Thu Aug 23 13:11:13 2018 -0700
+++ b/hgext/narrow/narrowcommands.py Mon Aug 06 14:06:19 2018 +0300
@@ -14,6 +14,7 @@
cmdutil,
commands,
discovery,
+ encoding,
error,
exchange,
extensions,
@@ -326,6 +327,7 @@
[('', 'addinclude', [], _('new paths to include')),
('', 'removeinclude', [], _('old paths to no longer include')),
('', 'addexclude', [], _('new paths to exclude')),
+ ('', 'import-rules', '', _('import narrowspecs from a file')),
('', 'removeexclude', [], _('old paths to no longer exclude')),
('', 'clear', False, _('whether to replace the existing narrowspec')),
('', 'force-delete-local-changes', False,
@@ -369,6 +371,23 @@
ui.warn(_('The --clear option is not yet supported.\n'))
return 1
+ # import rules from a file
+ newrules = opts.get('import_rules')
+ if newrules:
+ try:
+ filepath = os.path.join(pycompat.getcwd(), newrules)
+ fdata = util.readfile(filepath)
+ except IOError as inst:
+ raise error.Abort(_("cannot read narrowspecs from '%s': %s") %
+ (filepath, encoding.strtolocal(inst.strerror)))
+ includepats, excludepats, profiles = sparse.parseconfig(ui, fdata,
+ 'narrow')
+ if profiles:
+ raise error.Abort(_("including other spec files using '%include' "
+ "is not supported in narrowspec"))
+ opts['addinclude'].extend(includepats)
+ opts['addexclude'].extend(excludepats)
+
if narrowspec.needsexpansion(opts['addinclude'] + opts['addexclude']):
raise error.Abort('Expansion not yet supported on widen/narrow')