Ryan Lane has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/94688


Change subject: Add recursive submodule support to trebuchet
......................................................................

Add recursive submodule support to trebuchet

For repos using checkout_submodule this change makes submodule
checkout recursive.

Change-Id: Id24ebae89d5a41782ab3d8da81185d13302156e9
---
M modules/deployment/files/modules/deploy.py
1 file changed, 42 insertions(+), 31 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/88/94688/1

diff --git a/modules/deployment/files/modules/deploy.py 
b/modules/deployment/files/modules/deploy.py
index df6fb35..ae3a7ad 100644
--- a/modules/deployment/files/modules/deploy.py
+++ b/modules/deployment/files/modules/deploy.py
@@ -156,23 +156,46 @@
 
 
 def _update_gitmodules(config, location, shadow=False):
-    gitmodules = '{0}/.gitmodules'.format(location)
-
-    cmd = '/usr/bin/git checkout .gitmodules'
-    status = __salt__['cmd.retcode'](cmd, location)
-    if status != 0:
-        return status
-
-    # Transform .gitmodules file based on defined seds
-    for before, after in config['submodule_sed_regex'].items():
+    gitmodules_list = __salt__['file.find'](location, name='.gitmodules')
+    for gitmodules in gitmodules_list:
+        gitmodules_dir = os.path.dirname(gitmodules)
+        cmd = '/usr/bin/git checkout .gitmodules'
+        status = __salt__['cmd.retcode'](cmd, gitmodules_dir)
+        if status != 0:
+            return status
         if shadow:
-            # When fetching a shadow reference, we want to use the repo's
-            # filesystem location rather than the deployment url.
-            repo_url = config['location']
+            # Tranform .gitmodules based on reference
+            submodules = []
+            f = open(gitmodules, 'r')
+            for line in f.readlines():
+                keyval = line.split(' = ')
+                if keyval[0].strip() == "path":
+                    submodules.append(keyval[1].strip())
+            f.close()
+            f.open(gitmodules, 'w')
+            reference_dir = gitmodules_dir.replace(location,
+                                                   config['location'])
+            for submodule in submodules:
+                f.write('[submodule "{0}"]\n'.format(submodule))
+                f.write('\tpath = {0}\n'.format(submodule))
+                f.write('\turl = {0}/{1}\n'.format(reference_dir, submodule))
+            f.close()
         else:
-            repo_url = config['url']
-        after = after.replace('__REPO_URL__', repo_url)
-        __salt__['file.sed'](gitmodules, before, after)
+            # Transform .gitmodules file based on defined seds
+            for before, after in config['submodule_sed_regex'].items():
+                if shadow:
+                    # When fetching a shadow reference, we want to use the 
repo's
+                    # filesystem location rather than the deployment url.
+                    repo_url = config['location']
+                else:
+                    repo_url = config['url']
+                after = after.replace('__REPO_URL__', repo_url)
+                __salt__['file.sed'](gitmodules, before, after)
+        # Sync submodules for this repo
+        cmd = '/usr/bin/git submodule sync'
+        status = __salt__['cmd.retcode'](cmd, gitmodules_dir)
+        if status != 0:
+            return status
     return 0
 
 
@@ -260,20 +283,14 @@
         if ret != 0:
             return ret
 
-        # Sync the .gitmodules config
-        cmd = '/usr/bin/git submodule sync'
+        # fetch all submodules and tag for submodules
+        cmd = '/usr/bin/git submodule foreach --recursive git fetch'
         status = __salt__['cmd.retcode'](cmd, location)
         if status != 0:
             return status
 
         # fetch all submodules and tag for submodules
-        cmd = '/usr/bin/git submodule foreach git fetch'
-        status = __salt__['cmd.retcode'](cmd, location)
-        if status != 0:
-            return status
-
-        # fetch all submodules and tag for submodules
-        cmd = '/usr/bin/git submodule foreach git fetch --tags'
+        cmd = '/usr/bin/git submodule foreach --recursive git fetch --tags'
         status = __salt__['cmd.retcode'](cmd, location)
         if status != 0:
             return status
@@ -353,14 +370,8 @@
         if ret != 0:
             return ret
 
-        # Sync the .gitmodules config
-        cmd = '/usr/bin/git submodule sync'
-        ret = __salt__['cmd.retcode'](cmd, location)
-        if ret != 0:
-            return 40
-
         # Update the submodules to match this tag
-        cmd = '/usr/bin/git submodule update --init'
+        cmd = '/usr/bin/git submodule update --recursive --init'
         ret = __salt__['cmd.retcode'](cmd, location)
         if ret != 0:
             return 50

-- 
To view, visit https://gerrit.wikimedia.org/r/94688
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id24ebae89d5a41782ab3d8da81185d13302156e9
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Ryan Lane <rl...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to