narrow: consider empty commits to be "inside the narrow spec" for templates
authorDanny Hooper <hooper@google.com>
Mon, 20 May 2019 18:09:41 -0700
changeset 42358 45c18f7345c1
parent 42357 5b795108dd17
child 42359 563cd9a72682
narrow: consider empty commits to be "inside the narrow spec" for templates It doesn't seem useful to exclude them, or harmful to include them. Users writing log templates using outsidenarrow as a predicate might consider it unexpected if their locally created empty drafts are treated as if they contained something outside the clone. Differential Revision: https://phab.mercurial-scm.org/D6414
hgext/narrow/narrowtemplates.py
tests/test-narrow.t
--- a/hgext/narrow/narrowtemplates.py	Tue May 21 20:07:20 2019 +0200
+++ b/hgext/narrow/narrowtemplates.py	Mon May 20 18:09:41 2019 -0700
@@ -37,7 +37,7 @@
     repo = context.resource(mapping, 'repo')
     ctx = context.resource(mapping, 'ctx')
     m = repo.narrowmatch()
-    if not m.always():
+    if ctx.files() and not m.always():
         if not any(m(f) for f in ctx.files()):
             return 'outsidenarrow'
     return ''
--- a/tests/test-narrow.t	Tue May 21 20:07:20 2019 +0200
+++ b/tests/test-narrow.t	Mon May 20 18:09:41 2019 -0700
@@ -281,6 +281,10 @@
   marked working directory as branch foo
   (branches are permanent and global, did you want a bookmark?)
   $ hg ci -m empty
+  $ hg log -T "{rev}: {desc} {outsidenarrow}\n"
+  2: empty 
+  1: add d5/f outsidenarrow
+  0: add d0/f outsidenarrow
   $ hg pull -q
 Can widen the empty clone
   $ hg tracked --addinclude d0