def ensure_workingdir(self, parent_dir, workdir, branch=None):
cur_dir = os.getcwd()
+ has_cloned = False
try:
os.chdir(parent_dir)
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)
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__":