From 464246d81ed2855ac051d96480910176e9419465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Massart?= Date: Tue, 29 Mar 2022 13:21:47 +0800 Subject: [PATCH] Adding experimental setting to clone with --shared flag --- mdk/config-dist.json | 6 ++++++ mdk/workplace.py | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/mdk/config-dist.json b/mdk/config-dist.json index 908d605..75d6865 100644 --- a/mdk/config-dist.json +++ b/mdk/config-dist.json @@ -301,6 +301,12 @@ // by this setting. "useCacheAsUpstreamRemote": true, + // Clones the cached repository with the option --shared, which drastically reduces the + // size of the .git/ folder in each of the Moodle instances. Git reports this as a possible + // dangerous operation (https://git-scm.com/docs/git-clone) so it is not enabled by default. + // This requires the useCacheAsUpstreamRemote to be enabled. + "useCacheAsSharedClone": false, + // You should not edit this, this is the branch that is considered as master by developers. "masterBranch": 400, diff --git a/mdk/workplace.py b/mdk/workplace.py index 533e6da..2940eee 100644 --- a/mdk/workplace.py +++ b/mdk/workplace.py @@ -132,6 +132,9 @@ def create(self, name=None, version='master', integration=False, useCacheAsRemot extraLinkDir = os.path.join(self.getMdkWebDir(), name) branch = stableBranch(version) + useCacheAsUpstream = C.get('useCacheAsUpstreamRemote') + cloneAsShared = useCacheAsUpstream and C.get('useCacheAsSharedClone') + if self.isMoodle(name): raise CreateException('The Moodle instance %s already exists' % name) elif os.path.isdir(installDir): @@ -148,7 +151,8 @@ def create(self, name=None, version='master', integration=False, useCacheAsRemot # Clone the instances logging.info('Cloning repository...') - process(f'{C.get("git")} clone --branch {branch} --single-branch {repository} {wwwDir}') + process(f'{C.get("git")} clone --branch {branch} --single-branch ' + f'{"--shared" if cloneAsShared else ""} {repository} {wwwDir}') # Symbolic link if os.path.islink(linkDir): @@ -191,7 +195,7 @@ def create(self, name=None, version='master', integration=False, useCacheAsRemot # Fixing up remote URLs if need be, this is done after pulling the cache one because we # do not want to contact the real origin server from here, it is slow and pointless. - if not C.get('useCacheAsUpstreamRemote'): + if not useCacheAsUpstream: realupstream = C.get('remotes.integration') if integration else C.get('remotes.stable') if realupstream: repo.setRemote(C.get('upstreamRemote'), realupstream)