1
0
Fork 1
mirror of https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git synced 2025-07-13 11:29:46 +03:00

aportgen: Allow retaining current branch when forking Alpine (MR 2271)

Often I find myself confused and subsequently frustrated by the
behaviour of --fork-alpine as usually I apply whatever changes I want to
the aports package before forking. This is due to that in the proper
aports repo I can leverage the full power of git and apply patches or
revert commits, whereas after the package has been forked to pmaports
the context git needs to do this is lost.

To fix that, this commit introduces --fork-alpine-retain-branch which
works the same way as --fork-alpine except it doesn't change the aports
branch to match the current channel.
This commit is contained in:
Newbyte 2024-03-09 18:42:55 +01:00 committed by Oliver Smith
parent 96da7f161a
commit d63ea90f2b
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
2 changed files with 31 additions and 15 deletions

View file

@ -165,18 +165,22 @@ def get_upstream_aport(args, pkgname, arch=None):
pmb.helpers.git.clone(args, "aports_upstream")
aports_upstream_path = args.work + "/cache_git/aports_upstream"
# Checkout branch
channel_cfg = pmb.config.pmaports.read_config_channel(args)
branch = channel_cfg["branch_aports"]
logging.info(f"Checkout aports.git branch: {branch}")
if pmb.helpers.run.user(args, ["git", "checkout", branch],
aports_upstream_path, check=False):
logging.info("NOTE: run 'pmbootstrap pull' and try again")
logging.info("NOTE: if it still fails, your aports.git was cloned with"
" an older version of pmbootstrap, as shallow clone."
" Unshallow it, or remove it and let pmbootstrap clone it"
f" again: {aports_upstream_path}")
raise RuntimeError("Branch checkout failed.")
if hasattr(args, "fork_alpine_retain_branch") and args.fork_alpine_retain_branch:
logging.info("Not changing aports branch as --fork-alpine-retain-branch was "
"used.")
else:
# Checkout branch
channel_cfg = pmb.config.pmaports.read_config_channel(args)
branch = channel_cfg["branch_aports"]
logging.info(f"Checkout aports.git branch: {branch}")
if pmb.helpers.run.user(args, ["git", "checkout", branch],
aports_upstream_path, check=False):
logging.info("NOTE: run 'pmbootstrap pull' and try again")
logging.info("NOTE: if it still fails, your aports.git was cloned with"
" an older version of pmbootstrap, as shallow clone."
" Unshallow it, or remove it and let pmbootstrap clone it"
f" again: {aports_upstream_path}")
raise RuntimeError("Branch checkout failed.")
# Search package
paths = glob.glob(aports_upstream_path + "/*/" + pkgname)

View file

@ -832,9 +832,15 @@ def arguments():
aportgen = sub.add_parser("aportgen", help="generate a postmarketOS"
" specific package build recipe"
" (aport/APKBUILD)")
aportgen.add_argument("--fork-alpine", help="fork the alpine upstream"
" package", action="store_true",
dest="fork_alpine")
aportgen_fork_alpine = aportgen.add_mutually_exclusive_group()
aportgen_fork_alpine.add_argument("--fork-alpine", help="fork the alpine upstream"
" package", action="store_true",
dest="fork_alpine")
aportgen_fork_alpine.add_argument("--fork-alpine-retain-branch",
help="fork the alpine upstream, but don't change "
"branch to match the current channel",
action="store_true",
dest="fork_alpine_retain_branch")
add_packages_arg(aportgen, nargs="+")
# Action: build
@ -930,6 +936,12 @@ def arguments():
args = parser.parse_args()
setattr(args, "from_argparse", copy.deepcopy(args))
setattr(args.from_argparse, "from_argparse", args.from_argparse)
if hasattr(args, "fork_alpine_retain_branch") and args.fork_alpine_retain_branch:
# fork_alpine_retain_branch largely matches the behaviour of fork_alpine, so
# just set fork_alpine here to reduce repetition.
args.fork_alpine = args.fork_alpine_retain_branch
pmb.helpers.args.init(args)
if getattr(args, "go_mod_cache", None) is None: