Ryan Lane has submitted this change and it was merged.

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/git-deploy/hooks/deploylib.py
M modules/deployment/files/modules/deploy.py
2 files changed, 46 insertions(+), 45 deletions(-)

Approvals:
  Ryan Lane: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/deployment/files/git-deploy/hooks/deploylib.py 
b/modules/deployment/files/git-deploy/hooks/deploylib.py
index e2630dd..b82f136 100755
--- a/modules/deployment/files/git-deploy/hooks/deploylib.py
+++ b/modules/deployment/files/git-deploy/hooks/deploylib.py
@@ -62,12 +62,12 @@
             print err
         # Ensure the fetch will work for the submodules
         if checkout_submodules:
-            p = subprocess.Popen('git submodule foreach "git tag %s"' % tag,
-                                 cwd=repodir, shell=True,
+            cmd = 'git submodule foreach --recursive "git tag {0}"'.format(tag)
+            p = subprocess.Popen(cmd, cwd=repodir, shell=True,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE)
             out = p.communicate()[0]
-            p = subprocess.Popen('git submodule foreach '
+            p = subprocess.Popen('git submodule foreach --recursive '
                                  '"submodule-update-server-info"',
                                  cwd=repodir, shell=True,
                                  stdout=subprocess.PIPE,
diff --git a/modules/deployment/files/modules/deploy.py 
b/modules/deployment/files/modules/deploy.py
index aff9441..0ff5ad8 100644
--- a/modules/deployment/files/modules/deploy.py
+++ b/modules/deployment/files/modules/deploy.py
@@ -77,7 +77,6 @@
     else:
         scheme = 'http'
     config['url'] = '{0}://{1}/{2}'.format(scheme, server, repo)
-    config.setdefault('submodule_sed_regex', {})
     config.setdefault('checkout_submodules', False)
     config.setdefault('dependencies', {})
     config.setdefault('checkout_module_calls', {})
@@ -156,23 +155,48 @@
 
 
 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
+        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()
         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
+            reference_dir = gitmodules_dir.replace(location,
+                                                   config['location'])
+            f = open(gitmodules, 'w')
+            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 url
+            cmd = '/usr/bin/git config remote.origin.url'
+            remote = __salt__['cmd.run'](cmd, gitmodules_dir)
+            if not remote:
+                return 1
+            f = open(gitmodules, 'w')
+            for submodule in submodules:
+                submodule_path = 'modules/{0}'.format(submodule)
+                f.write('[submodule "{0}"]\n'.format(submodule))
+                f.write('\tpath = {0}\n'.format(submodule))
+                f.write('\turl = {0}/{1}\n'.format(remote, submodule_path))
+            f.close()
+        # 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,12 +284,7 @@
 
 
 def _fetch_location(config, location, shadow=False):
-    cmd = '/usr/bin/git fetch'
-    status = __salt__['cmd.retcode'](cmd, location)
-    if status != 0:
-        return status
-
-    cmd = '/usr/bin/git fetch --tags'
+    cmd = '/usr/bin/git fetch --all'
     status = __salt__['cmd.retcode'](cmd, location)
     if status != 0:
         return status
@@ -277,20 +296,8 @@
         if ret != 0:
             return ret
 
-        # Sync the .gitmodules config
-        cmd = '/usr/bin/git submodule sync'
-        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 --all'
         status = __salt__['cmd.retcode'](cmd, location)
         if status != 0:
             return status
@@ -379,14 +386,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: merged
Gerrit-Change-Id: Id24ebae89d5a41782ab3d8da81185d13302156e9
Gerrit-PatchSet: 9
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Ryan Lane <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Chad <[email protected]>
Gerrit-Reviewer: Ryan Lane <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to