hgext/narrow/narrowcommands.py
changeset 40436 30a7d3b6b281
parent 40074 f7011b44d205
child 40438 5d8f291405e5
--- a/hgext/narrow/narrowcommands.py	Tue Oct 23 14:26:17 2018 +0300
+++ b/hgext/narrow/narrowcommands.py	Tue Oct 23 16:24:04 2018 +0300
@@ -392,9 +392,21 @@
     removedincludes = narrowspec.parsepatterns(opts['removeinclude'])
     addedexcludes = narrowspec.parsepatterns(opts['addexclude'])
     removedexcludes = narrowspec.parsepatterns(opts['removeexclude'])
+
+    only_show = not (addedincludes or removedincludes or addedexcludes or
+                     removedexcludes or newrules)
+
+    oldincludes, oldexcludes = repo.narrowpats
+
+    # filter the user passed additions and deletions into actual additions and
+    # deletions of excludes and includes
+    addedincludes = set([i for i in addedincludes if i not in oldincludes])
+    removedincludes = set([i for i in removedincludes if i in oldincludes])
+    addedexcludes = set([i for i in addedexcludes if i not in oldexcludes])
+    removedexcludes = set([i for i in removedexcludes if i in oldexcludes])
+
     widening = addedincludes or removedexcludes
     narrowing = removedincludes or addedexcludes
-    only_show = not widening and not narrowing
 
     # Only print the current narrowspec.
     if only_show:
@@ -413,6 +425,10 @@
         fm.end()
         return 0
 
+    if not widening and not narrowing:
+        ui.status(_("nothing to widen or narrow\n"))
+        return 0
+
     with repo.wlock(), repo.lock():
         cmdutil.bailifchanged(repo)
 
@@ -432,7 +448,6 @@
 
         commoninc = discovery.findcommonincoming(repo, remote)
 
-        oldincludes, oldexcludes = repo.narrowpats
         if narrowing:
             newincludes = oldincludes - removedincludes
             newexcludes = oldexcludes | addedexcludes