diff --git a/bin/subrepo_checkout.py b/bin/subrepo_checkout.py new file mode 100755 index 0000000000000000000000000000000000000000..2d5afaddb6756ade3360ca6d8d6a638507754e8a --- /dev/null +++ b/bin/subrepo_checkout.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +#------------------------------------------------------------------------------------ +# SProject Subrepository Checkout Script +# A joint work commissioned on behalf of SoC Labs, under Arm Academic Access license. +# +# Contributors +# +# David Mapstone (d.a.mapstone@soton.ac.uk) +# Copyright (c) 2023, SoC Labs (www.soclabs.org) +#------------------------------------------------------------------------------------ +import argparse +import os + +class git_repo(): + def __init__(self, directory, branch): + self.directory = directory + self.branch = branch + +def read_branchfile(branchfile): + f = open(branchfile, "r") + filelines = f.readlines() + f.close() + sub_repos = [] + for line in filelines: + if not line.startswith("#"): + repo = line.replace(" ","").split(":") + if len(repo) == 2: + sub_repos.append(git_repo(repo[0],repo[1])) + + return sub_repos + +def repo_checkout(directory, branch): + os.system(f"cd {directory}; git checkout {branch}") + +if __name__ == "__main__": + # Capture Arguments from Command Line + parser = argparse.ArgumentParser(description='Checks out branches for subrepositories in a project') + parser.add_argument("-b", "--branchfile", type=str, help="File to Read in Branches from") + parser.add_argument("-t", "--topproject", type=str, help="Top-level directory of Project") + args = parser.parse_args() + sub_repos = read_branchfile(args.branchfile) + for repo in sub_repos: + repo_checkout(repo.directory, repo.branch)