changeset 47442:d1c1fd7ac46d

clone: use "official" API to create local clone destination This make sure we have a properly created, fully functional repository early. This will be useful to simply the hardlink/copy phases of the local clone to make it share more of its logic with the similar "stream" cloning. This has a minor impact of the test and the resulting repository has is better initialized (eg: the `wcache` directory is pre-created.) Differential Revision: https://phab.mercurial-scm.org/D10850
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 09 Jun 2021 01:10:34 +0200
parents e33c6dd346e7
children 9ab54aa56982
files mercurial/hg.py tests/test-empty.t tests/test-extension.t
diffstat 3 files changed, 12 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hg.py	Wed Jun 09 01:10:26 2021 +0200
+++ b/mercurial/hg.py	Wed Jun 09 01:10:34 2021 +0200
@@ -857,20 +857,17 @@
 
         if copy:
             srcrepo.hook(b'preoutgoing', throw=True, source=b'clone')
-            hgdir = os.path.realpath(os.path.join(dest, b".hg"))
-            if not os.path.exists(dest):
-                util.makedirs(dest)
-            try:
-                destpath = hgdir
-                util.makedir(destpath, notindexed=True)
-            except OSError as inst:
-                if inst.errno == errno.EEXIST:
-                    cleandir = None
-                    raise error.Abort(
-                        _(b"destination '%s' already exists") % dest
-                    )
-                raise
 
+            destrootpath = urlutil.urllocalpath(dest)
+            dest_reqs = localrepo.clone_requirements(ui, createopts, srcrepo)
+            localrepo.createrepository(
+                ui,
+                destrootpath,
+                requirements=dest_reqs,
+            )
+            destrepo = localrepo.makelocalrepository(ui, destrootpath)
+
+            destpath = destrepo.vfs.base
             destlock = copystore(ui, srcrepo, destpath)
             # copy bookmarks over
             srcbookmarks = srcrepo.vfs.join(b'bookmarks')
--- a/tests/test-empty.t	Wed Jun 09 01:10:26 2021 +0200
+++ b/tests/test-empty.t	Wed Jun 09 01:10:34 2021 +0200
@@ -48,6 +48,7 @@
   hgrc
   requires
   store
+  wcache
 
 Should be empty:
 
--- a/tests/test-extension.t	Wed Jun 09 01:10:26 2021 +0200
+++ b/tests/test-extension.t	Wed Jun 09 01:10:34 2021 +0200
@@ -111,6 +111,7 @@
   reposetup called for a
   ui == repo.ui
   uipopulate called (1 times)
+  uipopulate called (1 times)
   reposetup called for b
   ui == repo.ui
   updating to branch default