From 2c972c45ca8abd783fb0a06a7e769ecac8c2f852 Mon Sep 17 00:00:00 2001 From: Mathias Klette Date: Mon, 2 Jan 2012 23:48:23 +0100 Subject: [PATCH] OFFICE-797: adding submodule handling --- debian_build.py | 7 +++++++ lib/git_helper.py | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/debian_build.py b/debian_build.py index 5e6e261..f042b00 100755 --- a/debian_build.py +++ b/debian_build.py @@ -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') diff --git a/lib/git_helper.py b/lib/git_helper.py index f6020b5..fb3d74e 100644 --- a/lib/git_helper.py +++ b/lib/git_helper.py @@ -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: -- 2.39.5