hg: set default path correctly when doing a clone+share (
issue5378)
Before, if performing a clone+share from a repo that was itself
using shared storage, the share code would copy paths.default from
the underlying repo being shared, not from the source given by
the user.
This patch teaches hg.clonewithshare to resolve paths.default
and pass it to share so it can be written to the hgrc accordingly.
--- a/mercurial/hg.py Sat Oct 01 14:18:58 2016 +0100
+++ b/mercurial/hg.py Sun Oct 02 22:34:40 2016 -0700
@@ -195,7 +195,7 @@
return ''
return os.path.basename(os.path.normpath(path))
-def share(ui, source, dest=None, update=True, bookmarks=True):
+def share(ui, source, dest=None, update=True, bookmarks=True, defaultpath=None):
'''create a shared repository'''
if not islocal(source):
@@ -240,10 +240,10 @@
destvfs.write('sharedpath', sharedpath)
r = repository(ui, destwvfs.base)
- postshare(srcrepo, r, bookmarks=bookmarks)
+ postshare(srcrepo, r, bookmarks=bookmarks, defaultpath=defaultpath)
_postshareupdate(r, update, checkout=checkout)
-def postshare(sourcerepo, destrepo, bookmarks=True):
+def postshare(sourcerepo, destrepo, bookmarks=True, defaultpath=None):
"""Called after a new shared repo is created.
The new repo only has a requirements file and pointer to the source.
@@ -252,7 +252,7 @@
Extensions can wrap this function and write additional entries to
destrepo/.hg/shared to indicate additional pieces of data to be shared.
"""
- default = sourcerepo.ui.config('paths', 'default')
+ default = defaultpath or sourcerepo.ui.config('paths', 'default')
if default:
fp = destrepo.vfs("hgrc", "w", text=True)
fp.write("[paths]\n")
@@ -374,8 +374,15 @@
clone(ui, peeropts, source, dest=sharepath, pull=True,
rev=rev, update=False, stream=stream)
+ # Resolve the value to put in [paths] section for the source.
+ if islocal(source):
+ defaultpath = os.path.abspath(util.urllocalpath(source))
+ else:
+ defaultpath = source
+
sharerepo = repository(ui, path=sharepath)
- share(ui, sharerepo, dest=dest, update=False, bookmarks=False)
+ share(ui, sharerepo, dest=dest, update=False, bookmarks=False,
+ defaultpath=defaultpath)
# We need to perform a pull against the dest repo to fetch bookmarks
# and other non-store data that isn't shared by default. In the case of
--- a/tests/test-clone.t Sat Oct 01 14:18:58 2016 +0100
+++ b/tests/test-clone.t Sun Oct 02 22:34:40 2016 -0700
@@ -829,7 +829,7 @@
Default path should be source, not share.
$ hg -R share-dest1b config paths.default
- $TESTTMP/source1a (glob)
+ $TESTTMP/source1b (glob)
Checked out revision should be head of default branch