# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 2020-07-01 09:44:59 # Node ID 88a47cbf063c9f750cc6b5ade136964dd3f1d407 # Parent fd1de908f2b45faf04248fb8d7c2e54f5d84334e config: add a .hg/hgrc-not-shared which won't be shared in share-safe mode Previous patches add a safe mode for sharing repositories which involve sharing of source requirements and config files. In certain situations we might need to add a config to source repository which we does not want to share. For this, we add a `.hg/hgrc-not-shared` which won't be shared. This also adds a `--non-shared` flag to `hg config` command to see the non-shared config. Differential Revision: https://phab.mercurial-scm.org/D8673 diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2139,6 +2139,7 @@ def _docommit(ui, repo, *pats, **opts): None, _(b'edit shared source repository config (EXPERIMENTAL)'), ), + (b'', b'non-shared', None, _(b'edit non shared config (EXPERIMENTAL)')), (b'g', b'global', None, _(b'edit global config')), ] + formatteropts, @@ -2169,6 +2170,9 @@ def config(ui, repo, *values, **opts): .. container:: verbose + --non-shared flag is used to edit `.hg/hgrc-not-shared` config file. + This file is not shared across shares when in share-safe mode. + Template: The following keywords are supported. See also :hg:`help templates`. @@ -2186,7 +2190,7 @@ def config(ui, repo, *values, **opts): """ opts = pycompat.byteskwargs(opts) - editopts = (b'edit', b'local', b'global', b'shared') + editopts = (b'edit', b'local', b'global', b'shared', b'non_shared') if any(opts.get(o) for o in editopts): cmdutil.check_at_most_one_arg(opts, *editopts[1:]) if opts.get(b'local'): @@ -2208,6 +2212,8 @@ def config(ui, repo, *values, **opts): ) ) paths = [vfsmod.vfs(repo.sharedpath).join(b'hgrc')] + elif opts.get(b'non_shared'): + paths = [repo.vfs.join(b'hgrc-not-shared')] else: paths = rcutil.userrcpath() diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -987,6 +987,7 @@ def _getlocal(ui, rpath, wd=None): if rcutil.use_repo_hgrc(): _readsharedsourceconfig(lui, path) lui.readconfig(os.path.join(path, b".hg", b"hgrc"), path) + lui.readconfig(os.path.join(path, b".hg", b"hgrc-not-shared"), path) if rpath: path = lui.expandpath(rpath) @@ -994,6 +995,7 @@ def _getlocal(ui, rpath, wd=None): if rcutil.use_repo_hgrc(): _readsharedsourceconfig(lui, path) lui.readconfig(os.path.join(path, b".hg", b"hgrc"), path) + lui.readconfig(os.path.join(path, b".hg", b"hgrc-not-shared"), path) return path, lui diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -715,18 +715,28 @@ def loadhgrc(ui, wdirvfs, hgvfs, require if not rcutil.use_repo_hgrc(): return False + ret = False # first load config from shared source if we has to if requirementsmod.SHARESAFE_REQUIREMENT in requirements and sharedvfs: try: ui.readconfig(sharedvfs.join(b'hgrc'), root=sharedvfs.base) + ret = True except IOError: pass try: ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base) - return True + ret = True except IOError: - return False + pass + + try: + ui.readconfig(hgvfs.join(b'hgrc-not-shared'), root=wdirvfs.base) + ret = True + except IOError: + pass + + return ret def afterhgrcload(ui, wdirvfs, hgvfs, requirements): diff --git a/tests/test-completion.t b/tests/test-completion.t --- a/tests/test-completion.t +++ b/tests/test-completion.t @@ -259,7 +259,7 @@ Show all commands + options cat: output, rev, decode, include, exclude, template clone: noupdate, updaterev, rev, branch, pull, uncompressed, stream, ssh, remotecmd, insecure commit: addremove, close-branch, amend, secret, edit, force-close-branch, interactive, include, exclude, message, logfile, date, user, subrepos - config: untrusted, edit, local, shared, global, template + config: untrusted, edit, local, shared, non-shared, global, template continue: dry-run copy: forget, after, at-rev, force, include, exclude, dry-run debugancestor: diff --git a/tests/test-share-safe.t b/tests/test-share-safe.t --- a/tests/test-share-safe.t +++ b/tests/test-share-safe.t @@ -253,6 +253,25 @@ Shared one should work date: Thu Jan 01 00:00:00 1970 +0000 summary: added c + +Testing that nonsharedrc is loaded for source and not shared + + $ cd ../source + $ touch .hg/hgrc-not-shared + $ echo "[ui]" >> .hg/hgrc-not-shared + $ echo "traceback=true" >> .hg/hgrc-not-shared + + $ hg showconfig ui.traceback + true + + $ HGEDITOR=cat hg config --non-shared + [ui] + traceback=true + + $ cd ../shared1 + $ hg showconfig ui.traceback + [1] + Unsharing works $ hg unshare