Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bulk: few fixes and improvements #58

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions depends_on/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import os
import re
import subprocess
import sys
import urllib.parse
from urllib.request import Request, urlopen
Expand Down Expand Up @@ -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):
Expand Down
11 changes: 9 additions & 2 deletions depends_on_stage2
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand Down Expand Up @@ -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):
Expand Down
Loading