File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -279,16 +279,21 @@ def temporary_checkout(revision: str):
279
279
happen along the way.
280
280
"""
281
281
with TemporaryDirectory () as tmp_dir :
282
+ basename = Path (tmp_dir ).name
283
+ ret , _ , _ = utils .run_cmd (
284
+ f"git cat-file -t { revision } " , ignore_return_code = True
285
+ )
286
+ if ret != 0 :
287
+ # git didn't recognize this object, so maybe it is a branch; qualify it
288
+ revision = f"origin/{ revision } "
289
+ # make a temp branch for that commit so we can directly check it out
290
+ utils .run_cmd (f"git branch { basename } { revision } " )
282
291
# `git clone` can take a path instead of an URL, which causes it to create a copy of the
283
292
# repository at the given path. However, that path needs to point to the root of a repository,
284
293
# it cannot be some arbitrary subdirectory. Therefore:
285
294
_ , git_root , _ = utils .run_cmd ("git rev-parse --show-toplevel" )
286
295
# split off the '\n' at the end of the stdout
287
- utils .run_cmd (f"git clone { git_root .strip ()} { tmp_dir } " )
288
-
289
- with chdir (tmp_dir ):
290
- utils .run_cmd (f"git checkout { revision } " )
291
-
296
+ utils .run_cmd (f"git clone -b { basename } { git_root .strip ()} { tmp_dir } " )
292
297
yield Path (tmp_dir )
293
298
294
299
# If we compiled firecracker inside the checkout, python's recursive shutil.rmdir will
You can’t perform that action at this time.
0 commit comments