From 3a09a2ed29c05eaa66a010405f9e609951bf5238 Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Sun, 10 Jan 2016 20:30:02 +0300 Subject: [PATCH] Add a script that prints submodules info in Glockfile compatible format --- submodules-to-glockfile.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 submodules-to-glockfile.py diff --git a/submodules-to-glockfile.py b/submodules-to-glockfile.py new file mode 100755 index 0000000..60fd4b9 --- /dev/null +++ b/submodules-to-glockfile.py @@ -0,0 +1,23 @@ +#!/usr/bin/python + +import re +import subprocess + +def main(): + source = open(".gitmodules").read() + paths = re.findall(r"path = (.*)", source) + + for path in paths: + print "{repo} {sha}".format( + repo = path[7:], + sha = path_sha1(path) + ) + +def path_sha1(path): + cmd = "cd {} && git rev-parse HEAD".format(path) + sp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) + sha1 = sp.stdout.read()[:-1] + + return sha1 + +if __name__ == "__main__": main()