From 8ac6b154a6a8f98a5b0fe314182aaaddce1cd0f9 Mon Sep 17 00:00:00 2001
From: dam1n19 <dam1n19@soton.ac.uk>
Date: Wed, 5 Jul 2023 10:45:48 +0100
Subject: [PATCH] Added recursive projbranch files

---
 bin/subrepo_checkout.py | 15 +++++++++++++--
 projbranch              | 13 +++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)
 create mode 100644 projbranch

diff --git a/bin/subrepo_checkout.py b/bin/subrepo_checkout.py
index a689d9b..a2cb19a 100755
--- a/bin/subrepo_checkout.py
+++ b/bin/subrepo_checkout.py
@@ -11,6 +11,8 @@
 import argparse
 import os
 
+from os.path import exists
+
 class git_repo():
     def __init__(self, directory, branch):
         self.directory = directory
@@ -28,10 +30,19 @@ def read_branchfile(branchfile):
                 sub_repos.append(git_repo(repo[0],repo[1]))
             
     return sub_repos
+
+def find_branchfile(directory, branchfile):
+    if exists(f"{directory}/{branchfile}"):
+        print(f"Found Branchfile in {directory}")
+        sub_repos = read_branchfile(f"{directory}/{branchfile}")
+        for repo in sub_repos:
+            print(f"Subrepo found: {repo.directory}")
+            repo_checkout(f"{directory}/{repo.directory}", repo.branch, branchfile)
     
-def repo_checkout(directory, branch):
+def repo_checkout(directory, branch, branchfile):
     print(f"Checking out {directory} to branch {branch}")
     os.system(f"cd {directory}; git checkout {branch}")
+    find_branchfile(directory, branchfile)
     
 if __name__ == "__main__":
     # Capture Arguments from Command Line
@@ -41,4 +52,4 @@ if __name__ == "__main__":
     args = parser.parse_args()
     sub_repos = read_branchfile(args.branchfile)
     for repo in sub_repos:
-        repo_checkout(repo.directory, repo.branch)
+        repo_checkout(repo.directory, repo.branch, args.branchfile)
diff --git a/projbranch b/projbranch
new file mode 100644
index 0000000..cf87447
--- /dev/null
+++ b/projbranch
@@ -0,0 +1,13 @@
+#-----------------------------------------------------------------------------
+# SoC Labs Sub repository branch setup
+# A joint work commissioned on behalf of SoC Labs, under Arm Academic Access license.
+#
+# Contributors
+#
+# David Mapstone (d.a.mapstone@soton.ac.uk)
+#
+# Copyright  2023, SoC Labs (www.soclabs.org)
+#-----------------------------------------------------------------------------
+# Each Repo needs to have its branch set manually in here - they will defaultly be checked out to main
+
+tools/chipkit_flow: main
\ No newline at end of file
-- 
GitLab