Skip to content

Commit

Permalink
Adding experimental setting to clone with --shared flag
Browse files Browse the repository at this point in the history
  • Loading branch information
FMCorz committed Mar 29, 2022
1 parent bbfab5d commit 464246d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions mdk/config-dist.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
8 changes: 6 additions & 2 deletions mdk/workplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 464246d

Please sign in to comment.