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):
279279 happen along the way.
280280 """
281281 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 } " )
282291 # `git clone` can take a path instead of an URL, which causes it to create a copy of the
283292 # repository at the given path. However, that path needs to point to the root of a repository,
284293 # it cannot be some arbitrary subdirectory. Therefore:
285294 _ , git_root , _ = utils .run_cmd ("git rev-parse --show-toplevel" )
286295 # 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 } " )
292297 yield Path (tmp_dir )
293298
294299 # 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