pull: fix aports branches not being recognized (MR 2252)

Fix for:
  $ pmbootstrap pull
  [21:09:43] aports_upstream (branch: 3.20-stable): not on one of the official branches (master), skipping pull!

Replace the get_branches_official() function that according to git log
was never able to tell if an aports branch was official. The new
function branch_looks_official() can do that by just checking if the
branch follows the typical naming pattern.

The comment I had put into get_branches_official earlier was not true
anymore, by now this did not only get used by "pmbootstrap status", but
also by "pmbootstrap pull".
This commit is contained in:
Oliver Smith 2024-06-20 21:07:11 +02:00
parent ef594ddf24
commit 794048e2d5
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
2 changed files with 26 additions and 23 deletions

View file

@ -152,12 +152,10 @@ def read_config_channel():
# Channel not in channels.cfg, try to be helpful # Channel not in channels.cfg, try to be helpful
branch = pmb.helpers.git.rev_parse(aports, branch = pmb.helpers.git.rev_parse(aports,
extra_args=["--abbrev-ref"]) extra_args=["--abbrev-ref"])
branches_official = pmb.helpers.git.get_branches_official(aports)
branches_official = ", ".join(branches_official)
remote = pmb.helpers.git.get_upstream_remote(aports) remote = pmb.helpers.git.get_upstream_remote(aports)
logging.info("NOTE: fix the error by rebasing or cherry picking relevant" logging.info("NOTE: fix the error by rebasing or cherry picking relevant"
" commits from this branch onto a branch that is on a" " commits from this branch onto a branch that is on a"
f" supported channel: {branches_official}") f" supported channel: master, v24.06, …")
logging.info("NOTE: as workaround, you may pass --config-channels with a" logging.info("NOTE: as workaround, you may pass --config-channels with a"
" custom channels.cfg. Reference:" " custom channels.cfg. Reference:"
" https://postmarketos.org/channels.cfg") " https://postmarketos.org/channels.cfg")

View file

@ -1,4 +1,4 @@
# Copyright 2023 Oliver Smith # Copyright 2024 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import configparser import configparser
from pathlib import Path from pathlib import Path
@ -7,6 +7,7 @@ from pmb.core.context import get_context
from pmb.core.pkgrepo import pkgrepo_path from pmb.core.pkgrepo import pkgrepo_path
from pmb.helpers import logging from pmb.helpers import logging
import os import os
import re
import pmb.build import pmb.build
import pmb.chroot.apk import pmb.chroot.apk
@ -15,6 +16,9 @@ import pmb.helpers.pmaports
import pmb.helpers.run import pmb.helpers.run
from pmb.meta import Cache from pmb.meta import Cache
re_branch_aports = re.compile(r"^\d+\.\d\d+-stable$")
re_branch_pmaports = re.compile(r"^v\d\d\.\d\d$")
def get_path(name_repo: str): def get_path(name_repo: str):
"""Get the path to the repository. """Get the path to the repository.
@ -154,22 +158,21 @@ def parse_channels_cfg(aports: Path):
return ret return ret
def get_branches_official(repo: Path): def branch_looks_official(repo: Path, branch):
"""Get all branches that point to official release channels. """Check if a given branch follows the patterns of official branches in
pmaports or aports.
:returns: list of supported branches, e.g. ["master", "3.11"] :returns: True if it looks official, False otherwise
""" """
# This functions gets called with pmaports and aports_upstream, because if branch == "master":
# both are displayed in "pmbootstrap status". But it only makes sense return True
# to display pmaports there, related code will be refactored soon (#1903). if repo.parts[-1] == "pmaports":
if repo.parts[-1] != "pmaports": if re_branch_pmaports.match(branch):
return ["master"] return True
else:
channels_cfg = parse_channels_cfg(repo) if re_branch_aports.match(branch):
ret = [] return True
for channel, channel_data in channels_cfg["channels"].items(): return False
ret.append(channel_data["branch_pmaports"])
return ret
def pull(repo_name: str): def pull(repo_name: str):
@ -182,7 +185,6 @@ def pull(repo_name: str):
:returns: integer, >= 0 on success, < 0 on error :returns: integer, >= 0 on success, < 0 on error
""" """
repo = get_path(repo_name) repo = get_path(repo_name)
branches_official = get_branches_official(repo)
# Skip if repo wasn't cloned # Skip if repo wasn't cloned
if not os.path.exists(repo): if not os.path.exists(repo):
@ -192,10 +194,13 @@ def pull(repo_name: str):
# Skip if not on official branch # Skip if not on official branch
branch = rev_parse(repo, extra_args=["--abbrev-ref"]) branch = rev_parse(repo, extra_args=["--abbrev-ref"])
msg_start = "{} (branch: {}):".format(repo_name, branch) msg_start = "{} (branch: {}):".format(repo_name, branch)
if branch not in branches_official: if not branch_looks_official(repo, branch):
logging.warning("{} not on one of the official branches ({}), skipping" if repo.parts[-1] == "pmaports":
" pull!" official_looking_branches = "master, v24.06, …"
"".format(msg_start, ", ".join(branches_official))) else:
official_looking_branches = "master, 3.20-stable, …"
logging.warning(f"{msg_start} not on one of the official branches"
f" ({official_looking_branches}), skipping pull!")
return -1 return -1
# Skip if workdir is not clean # Skip if workdir is not clean