paths: add a `*` special path to define default sub option
authorPierre-Yves David <pierre-yves.david@octobus.net>
Thu, 11 Mar 2021 11:22:54 +0100
changeset 46721 e3f15c553522
parent 46720 66fb04552122
child 46722 08a35cec14d4
paths: add a `*` special path to define default sub option Differential Revision: https://phab.mercurial-scm.org/D10163
mercurial/ui.py
tests/test-default-push.t
--- a/mercurial/ui.py	Thu Mar 11 17:26:49 2021 +0100
+++ b/mercurial/ui.py	Thu Mar 11 11:22:54 2021 +0100
@@ -2190,12 +2190,16 @@
     def __init__(self, ui):
         dict.__init__(self)
 
+        _path, base_sub_options = ui.configsuboptions(b'paths', b'*')
         for name, loc in ui.configitems(b'paths', ignoresub=True):
             # No location is the same as not existing.
             if not loc:
                 continue
             loc, sub = ui.configsuboptions(b'paths', name)
-            self[name] = path(ui, name, rawloc=loc, suboptions=sub)
+            sub_opts = base_sub_options.copy()
+            sub_opts.update(sub)
+            self[name] = path(ui, name, rawloc=loc, suboptions=sub_opts)
+        self._default_sub_opts = base_sub_options
 
     def getpath(self, ui, name, default=None):
         """Return a ``path`` from a string, falling back to default.
@@ -2230,7 +2234,9 @@
             # Try to resolve as a local path or URI.
             try:
                 # we pass the ui instance are warning might need to be issued
-                return path(ui, None, rawloc=name)
+                return path(
+                    ui, None, rawloc=name, suboptions=self._default_sub_opts
+                )
             except ValueError:
                 raise error.RepoError(_(b'repository %s does not exist') % name)
 
--- a/tests/test-default-push.t	Thu Mar 11 17:26:49 2021 +0100
+++ b/tests/test-default-push.t	Thu Mar 11 11:22:54 2021 +0100
@@ -146,4 +146,40 @@
     ^ here)
   [10]
 
+default :pushrev is taking in account
+
+  $ echo babar > foo
+  $ hg ci -m 'extra commit'
+  $ hg up '.^'
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ echo celeste > foo
+  $ hg ci -m 'extra other commit'
+  created new head
+  $ cat >> .hg/hgrc << EOF
+  > [paths]
+  > other = file://$WD/../pushurldest
+  > *:pushrev = .
+  > EOF
+  $ hg push other
+  pushing to file:/*/$TESTTMP/pushurlsource/../pushurldest (glob)
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  $ hg push file://$WD/../pushurldest
+  pushing to file:/*/$TESTTMP/pushurlsource/../pushurldest (glob)
+  searching for changes
+  no changes found
+  [1]
+
+for comparison, pushing everything would give different result
+
+  $ hg push file://$WD/../pushurldest --rev 'all()'
+  pushing to file:/*/$TESTTMP/pushurlsource/../pushurldest (glob)
+  searching for changes
+  abort: push creates new remote head 1616ce7cecc8
+  (merge or see 'hg help push' for details about pushing new heads)
+  [20]
+
   $ cd ..