diff --git a/depends_on/common.py b/depends_on/common.py index 2bbfc40..d40b027 100644 --- a/depends_on/common.py +++ b/depends_on/common.py @@ -3,6 +3,7 @@ import json import os import re +import subprocess import sys import urllib.parse from urllib.request import Request, urlopen @@ -347,8 +348,14 @@ def check_error(status, message): def command(cmd): "Execute a command" log(f"+ {cmd}") - ret = os.system(cmd) - check_error(ret == 0, f"Command failed with exit code {ret}") + try: + _ = subprocess.run( + cmd, shell=True, stderr=subprocess.PIPE, text=True, check=True + ) + except subprocess.CalledProcessError as e: + log(f"Command failed with exit code {e.returncode}") + log(e.stderr) + sys.exit(1) def is_gerrit(change_url): diff --git a/depends_on_stage2 b/depends_on_stage2 index 399c7e8..4b64c61 100755 --- a/depends_on_stage2 +++ b/depends_on_stage2 @@ -65,14 +65,17 @@ def extract_change(change_info, main_url, work_dir): ) else: return extract_github_change( - fork_url, - change_info["branch"], main_url, pr_number, work_dir, ) +def extract_default_branch(work_dir) -> str: + "Return the default branch of the git repository in work_dir." + return os.popen(f"cd {work_dir} && git rev-parse --abbrev-ref HEAD").read().strip() + + def main(check_mode): "Main function." @@ -154,6 +157,10 @@ def main(check_mode): # lookup if the remote of the directory is part of the depends_on # if yes, then we need to extract the right branch origin_url = extract_origin_url(real_extra_dir) + if not check_mode: + main_branch = extract_default_branch(real_extra_dir) + unshallow(real_extra_dir, main_branch) + merge_main_branch(real_extra_dir, main_branch) for depends_on_url in depends_on + [data["change_url"]]: log(f"depends_on_url: {depends_on_url} {origin_url}") if depends_on_url.startswith(origin_url):