Skip to content

Commit 8917575

Browse files
pb8owearyzen
authored andcommitted
fix: make A/B tests work in release branches
If we receive a branch, qualify it with `origin` before handing it to git. Signed-off-by: Pablo Barbáchano <pablob@amazon.com>
1 parent 036d990 commit 8917575

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

tests/framework/ab_test.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)