[Request] [+- ] D8659: config: add `--share` flag to edit config file of shared source
pulkit (Pulkit Goyal)
phabricator at mercurial-scm.org
Thu Jun 25 08:55:13 UTC 2020
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
With `format.exp-share-safe` enabled, we now read the `.hg/hgrc` of the shared
source also.
This patch adds `--share` flag to `hg config` command which can be used to edit
that shared source config file. It only works if the repository is shared one
and is shared using the safe method.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D8659
AFFECTED FILES
mercurial/commands.py
tests/test-share-safe.t
CHANGE DETAILS
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
@@ -33,6 +33,10 @@
$ hg ci -Aqm "added a"
$ echo b > b
$ hg ci -Aqm "added b"
+
+ $ HGEDITOR=cat hg config --share
+ abort: repository is not shared one, can't use --share
+ [255]
$ cd ..
Create a shared repo and check the requirements are shared and read correctly
@@ -85,4 +89,12 @@
$ hg showconfig ui.curses
false
+ $ HGEDITOR=cat hg config --share
+ [ui]
+ curses=true
+
+ $ HGEDITOR=cat hg config --local
+ [ui]
+ curses=false
+
$ hg unshare
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -44,6 +44,7 @@
hbisect,
help,
hg,
+ localrepo,
logcmdutil,
merge as mergemod,
mergestate as mergestatemod,
@@ -66,6 +67,7 @@
ui as uimod,
util,
verify as verifymod,
+ vfs as vfsmod,
wireprotoserver,
)
from .utils import (
@@ -2141,6 +2143,7 @@
(b'u', b'untrusted', None, _(b'show untrusted configuration options')),
(b'e', b'edit', None, _(b'edit user config')),
(b'l', b'local', None, _(b'edit repository config')),
+ (b'', b'share', None, _(b'edit share source config (EXPERIMENTAL)')),
(b'g', b'global', None, _(b'edit global config')),
]
+ formatteropts,
@@ -2179,22 +2182,34 @@
:source: String. Filename and line number where the item is defined.
:value: String. Config value.
+ The --share flag can be used to edit the config file of share source
+ repository. It only works when you have shared using the experimental safe
+ method.
+
Returns 0 on success, 1 if NAME does not exist.
"""
opts = pycompat.byteskwargs(opts)
- editopts = [b'edit', b'local', b'global']
+ editopts = [b'edit', b'local', b'global', b'share']
if any(opts.get(o) for o in editopts):
- if opts.get(b'local') and opts.get(b'global'):
- raise error.Abort(_(b"can't use --local and --global together"))
-
+ cmdutil.check_at_most_one_arg(opts, *editopts[1:])
if opts.get(b'local'):
if not repo:
raise error.Abort(_(b"can't use --local outside a repository"))
paths = [repo.vfs.join(b'hgrc')]
elif opts.get(b'global'):
paths = rcutil.systemrcpath()
+ elif opts.get(b'share'):
+ if not repo.shared():
+ raise error.Abort(
+ _(b"repository is not shared one, can't use --share")
+ )
+ if localrepo.SHARESAFE_REQUIREMENT not in repo.requirements:
+ raise error.Abort(
+ _(b"this does not support editing share source config")
+ )
+ paths = [vfsmod.vfs(repo.sharedpath).join(b'hgrc')]
else:
paths = rcutil.userrcpath()
To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20200625/c4d01e14/attachment-0001.html>
More information about the Mercurial-patches
mailing list