diff --git a/pmb/config/init.py b/pmb/config/init.py index 978bd370..56386a34 100644 --- a/pmb/config/init.py +++ b/pmb/config/init.py @@ -11,6 +11,7 @@ import pmb.config import pmb.config.pmaports import pmb.helpers.cli import pmb.helpers.devices +import pmb.helpers.git import pmb.helpers.http import pmb.helpers.logging import pmb.helpers.other @@ -653,6 +654,15 @@ def frontend(args): pmb.config.pmaports.switch_to_channel_branch(args, channel) cfg["pmbootstrap"]["is_default_channel"] = "False" + # Copy the git hooks if master was checked out. (Don't symlink them and + # only do it on master, so the git hooks don't change unexpectedly when + # having a random branch checked out.) + branch_current = pmb.helpers.git.rev_parse(args, args.aports, + extra_args=["--abbrev-ref"]) + if branch_current == "master": + logging.info("NOTE: pmaports is on master branch, copying git hooks.") + pmb.config.pmaports.install_githooks(args) + # Device device, device_exists, kernel, nonfree = ask_for_device(args) cfg["pmbootstrap"]["device"] = device diff --git a/pmb/config/pmaports.py b/pmb/config/pmaports.py index 43958b53..8e676994 100644 --- a/pmb/config/pmaports.py +++ b/pmb/config/pmaports.py @@ -191,3 +191,17 @@ def switch_to_channel_branch(args, channel_new): # Verify pmaports.cfg on new branch read_config(args) return True + + +def install_githooks(args): + hooks_dir = os.path.join(args.aports, ".githooks") + if not os.path.exists(hooks_dir): + logging.info("No .githooks dir found") + return + for h in os.listdir(hooks_dir): + src = os.path.join(hooks_dir, h) + # Use git default hooks dir so users can ignore our hooks + # if they dislike them by setting "core.hooksPath" git config + dst = os.path.join(args.aports, ".git", "hooks", h) + if pmb.helpers.run.user(args, ["cp", src, dst], check=False): + logging.warning(f"WARNING: Copying git hook failed: {dst}")