From: Frank Brehm Date: Wed, 27 Mar 2019 09:33:11 +0000 (+0100) Subject: Adding handling of GIT submodules in lib/webhooks/deploy.py X-Git-Tag: 1.0.3^2~1 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=63e696f05a23608dc7549065b2680eef1f45d780;p=pixelpark%2Fpuppetmaster-webhooks.git Adding handling of GIT submodules in lib/webhooks/deploy.py --- diff --git a/lib/webhooks/deploy.py b/lib/webhooks/deploy.py index fdbd0fd..b6d066d 100644 --- a/lib/webhooks/deploy.py +++ b/lib/webhooks/deploy.py @@ -223,6 +223,7 @@ class WebhookDeployApp(BaseHookApp): def ensure_workingdir(self, parent_dir, workdir, branch=None): cur_dir = os.getcwd() + has_cloned = False try: os.chdir(parent_dir) @@ -235,6 +236,7 @@ class WebhookDeployApp(BaseHookApp): cmd = ['git', 'clone', self.git_ssh_url, workdir] if branch: cmd += ['-b', branch] + has_cloned = True (ret_val, stdoutdata, stderrdata) = self.handler.call(cmd, sudo=self.do_sudo) @@ -251,9 +253,53 @@ class WebhookDeployApp(BaseHookApp): self.error_data.append(msg) self.print_out(msg) + if has_cloned: + os.chdir(workdir) + + # Handling Submodules ... + if os.path.isfile('.gitmodules'): + self.handle_submodules() + finally: os.chdir(cur_dir) + # ------------------------------------------------------------------------- + def handle_submodules(self): + + # Initialize the submodules recorded in the index + LOG.info("Initializing GIT submodules in working directory {!r}.".format(os.getcwd())) + cmd = ['git', 'submodule', 'init'] + (ret_val, stdoutdata, stderrdata) = self.handler.call(cmd, sudo=self.do_sudo) + if stdoutdata: + msg = "Output:\n{}".format(to_str(stdoutdata)) + self.print_out(msg) + else: + LOG.debug("No output.") + + if stderrdata: + cmd_str = ' '.join(map(lambda x: pipes.quote(x), cmd)) + msg = "Error messages on '{c}':\n{e}".format(c=cmd_str, e=to_str(stderrdata)) + if ret_val: + self.error_data.append(msg) + self.print_out(msg) + + # Update the registered submodules to match what the superproject expects + LOG.info("Updating GIT submodules in working directory {!r}.".format(os.getcwd())) + cmd = ['git', 'submodule', 'update', '--init', '--recursive'] + (ret_val, stdoutdata, stderrdata) = self.handler.call(cmd, sudo=self.do_sudo) + if stdoutdata: + msg = "Output:\n{}".format(to_str(stdoutdata)) + self.print_out(msg) + else: + LOG.debug("No output.") + + if stderrdata: + cmd_str = ' '.join(map(lambda x: pipes.quote(x), cmd)) + msg = "Error messages on '{c}':\n{e}".format(c=cmd_str, e=to_str(stderrdata)) + if ret_val: + self.error_data.append(msg) + self.print_out(msg) + # ============================================================================= if __name__ == "__main__":