@@ -130,7 +130,13 @@ def extract_tarball(tarball_path: str, extract_to: str):
130130 tar .extract (member , path = extract_to , filter = "tar" )
131131
132132
133- def fetch_tarball_and_submodules (repo_url , commit , base_path = None , filter = "." ):
133+ def fetch_tarball_and_submodules (
134+ repo_url ,
135+ commit ,
136+ base_path = None ,
137+ filter = "." ,
138+ add_gitcommit = False ,
139+ ):
134140 if base_path is None :
135141 base_path = urllib .parse .urlsplit (repo_url ).path .split ("/" )[- 1 ]
136142 key = (repo_url , commit )
@@ -155,6 +161,10 @@ def fetch_tarball_and_submodules(repo_url, commit, base_path=None, filter="."):
155161 tree_resp .raise_for_status ()
156162 tree_data = tree_resp .json ()
157163
164+ if add_gitcommit :
165+ with open (os .path .join (base_path , ".gitcommit" ), "w" ) as f :
166+ f .write (tree_data ["sha" ])
167+
158168 submodules = {
159169 item ["path" ]: item ["sha" ]
160170 for item in tree_data .get ("tree" , [])
@@ -215,6 +225,7 @@ def fetch_tarball_and_submodules(repo_url, commit, base_path=None, filter="."):
215225 commit = sha ,
216226 base_path = sub_path ,
217227 filter = filter ,
228+ add_gitcommit = add_gitcommit ,
218229 )
219230
220231 with open (
@@ -238,9 +249,15 @@ def fetch_tarball_and_submodules(repo_url, commit, base_path=None, filter="."):
238249 default = "." ,
239250 help = "Regex to match submodule paths. Submodules that are not matched will be excluded." ,
240251)
252+ @click .option (
253+ "--add-gitcommit" ,
254+ default = False ,
255+ is_flag = True ,
256+ help = "Adds a .gitcommit file containing the commit sha256 of each resolved tree" ,
257+ )
241258@click .argument ("repo_url" )
242259@click .argument ("commit" )
243- def main (repo_url , commit , out_dir , filter ):
260+ def main (repo_url , commit , out_dir , filter , add_gitcommit ):
244261 """
245262 Downloads a snapshot of a GitHub repo, i.e. with all GitHub-based submodules
246263 recursively downloaded.
@@ -254,6 +271,7 @@ def main(repo_url, commit, out_dir, filter):
254271 commit = commit ,
255272 base_path = out_dir ,
256273 filter = filter ,
274+ add_gitcommit = add_gitcommit ,
257275 )
258276
259277
0 commit comments