]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
OFFICE-797: adding submodule handling
authorMathias Klette <mathias.klette@profitbricks.com>
Mon, 2 Jan 2012 22:48:23 +0000 (23:48 +0100)
committerMathias Klette <mathias.klette@profitbricks.com>
Mon, 2 Jan 2012 22:48:23 +0000 (23:48 +0100)
debian_build.py
lib/git_helper.py

index 5e6e26147fc3dc7a9ccf8edd8a10e7a9eb459dd7..f042b00afafb55f6d052d6f3a2c51d2103e18117 100755 (executable)
@@ -269,6 +269,13 @@ if __name__ == '__main__':
         logger_loud_error('git checkout %s was not successfull' % GIT_UPSTREAM_BRANCH)
         exit_error()
 
+    # now let's update submodules
+    if git_helper.git_checkout_submodule():
+        logger.info('git submodule completed')
+    else:
+        logger_loud_error('git submodule failed')
+        exit_error()
+
     # we need to make sure our jenkins config is used, so let's delete any 
     # other config available in repository that might be prefered 
     cleanup_files = ('.gbp.conf', 'debian/gbp.conf', '.git/gbp.conf')
index f6020b548ebf5a3a40f344e88bef600345746806..fb3d74ebcaf54a5a85d100b55020ebd296e72c3d 100644 (file)
@@ -151,6 +151,54 @@ def git_checkout_branch(branch_name):
     )
     return True
 
+def git_checkout_submodule():
+    """
+    Initialize and update any submodules which are used in the repository.
+    Git wont throw any errors when no submodules are used, so we can do it 
+    every time.
+    """
+    cmd = [GIT, 'submodule', 'init']
+    cmdobj = subprocess.Popen(
+            cmd,
+            shell=False,
+            close_fds=True,
+            stdout=subprocess.PIPE,
+            stderr=subprocess.STDOUT,
+            env={'':''},
+            cwd=os.getcwd()
+    )
+    ret = cmdobj.wait()
+    out = cmdobj.stdout.read()
+    msg = '%s returned %s: ' % (' '.join(cmd), ret, out)
+
+    if ret:
+        logger.error(msg)
+        return False
+    else:
+        logger.info(msg)
+
+    cmd = [GIT, 'submodule', 'update']
+    cmdobj = subprocess.Popen(
+            cmd,
+            shell=False,
+            close_fds=True,
+            stdout=subprocess.PIPE,
+            stderr=subprocess.STDOUT,
+            env={'':''},
+            cwd=os.getcwd()
+    )
+    ret = cmdobj.wait()
+    out = cmdobj.stdout.read()
+    msg = '%s returned %s: ' % (' '.join(cmd), ret, out)
+
+    if ret:
+        logger.error(msg)
+        return False
+    else:
+        logger.info(msg)
+
+    return True
+
 def git_repo_has_branch(name):
     r = git.repo.Repo()
     for branch in r.branches: