Setting not to use the cache as upstream remote
authorFrederic Massart <fred@moodle.com>
Mon, 9 Sep 2013 07:12:55 +0000 (15:12 +0800)
committerFrederic Massart <fred@moodle.com>
Mon, 9 Sep 2013 07:12:55 +0000 (15:12 +0800)
config-dist.json
lib/commands/check.py
lib/workplace.py

index bffbed0..1fbeebd 100644 (file)
     // during an instance creation. If false, the symlink won't be created.
     "symlinkToData": false,
 
+    // By default MDK caches origin as a local mirror. It is much faster when it comes to upgrading
+    // a couple of instances at the same time. MDK will update the mirror as often as it needs to,
+    // but if you are not using MDK to upgrade your instances, you might want to disable this
+    // functionality to only rely on the real origin. Creating new instances will not be affected
+    // by this setting.
+    "useCacheAsUpstreamRemote": true,
+
     // You should not edit this, this is the branch that is considered as master by developers.
     "masterBranch": 26,
 
index a77f860..3a98700 100644 (file)
@@ -203,8 +203,8 @@ class CheckCommand(Command):
         print 'Checking remotes'
         remotes = {
             'mine': self.C.get('remotes.mine'),
-            'stable': self.Wp.getCachedRemote(),
-            'integration': self.Wp.getCachedRemote(True)
+            'stable': self.Wp.getCachedRemote() if self.C.get('useCacheAsUpstreamRemote') else self.C.get('remotes.stable'),
+            'integration': self.Wp.getCachedRemote(True) if self.C.get('useCacheAsUpstreamRemote') else self.C.get('remotes.integration')
         }
         myRemote = self.C.get('myRemote')
         upstreamRemote = self.C.get('upstreamRemote')
index d9bb020..58d2b0f 100644 (file)
@@ -93,10 +93,7 @@ class Workplace(object):
         os.mkdir(wwwDir, 0755)
         os.mkdir(dataDir, 0777)
 
-        if integration:
-            repository = os.path.join(self.cache, 'integration.git')
-        else:
-            repository = os.path.join(self.cache, 'moodle.git')
+        repository = self.getCachedRemote(integration)
 
         # Clone the instances
         logging.info('Cloning repository...')
@@ -106,7 +103,7 @@ class Workplace(object):
         if os.path.islink(linkDir):
             os.remove(linkDir)
         if os.path.isfile(linkDir) or os.path.isdir(linkDir):  # No elif!
-            logging.warning('Could not create symbolic link. Please manually create: ln -s %s %s' (wwwDir, linkDir))
+            logging.warning('Could not create symbolic link. Please manually create: ln -s %s %s' (wwwDir, linkDir))
         else:
             os.symlink(wwwDir, linkDir)
 
@@ -119,6 +116,9 @@ class Workplace(object):
         logging.info('Checking out branch...')
         repo = git.Git(wwwDir, C.get('git'))
 
+        # Removing the default remote origin coming from the clone
+        repo.delRemote('origin')
+
         # Setting up the correct remote names
         repo.setRemote(C.get('myRemote'), C.get('remotes.mine'))
         repo.setRemote(C.get('upstreamRemote'), repository)
@@ -133,6 +133,13 @@ class Workplace(object):
             repo.checkout(branch)
         repo.pull(remote=C.get('upstreamRemote'))
 
+        # 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'):
+            realupstream = C.get('remotes.integration') if integration else C.get('remotes.stable')
+            if realupstream:
+                repo.setRemote(C.get('upstreamRemote'), realupstream)
+
         M = self.get(name)
         return M