pmb.config.init: copy pmaports githooks to default git hooks dir
So that githooks can be used in pmaports without the risk that symlinks pose when checking out random branches from random people. The hooks are copied, only when doing "pmbootstrap init", selecting the edge channel and having the master branch checked out (not any other branch on the edge channel or on any other channel). Closes: pmaports#2055 Related: pmaports!4008 Signed-off-by: Pablo Correa Gómez <ablocorrea@hotmail.com> Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org> Reviewed-by: Clayton Craft <clayton@craftyguy.net> Co-developed-by: Oliver Smith <ollieparanoid@postmarketos.org> Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3CDB9P192MB129107CAA025F4EF59D3FB53C7999@DB9P192MB1291.EURP192.PROD.OUTLOOK.COM%3E
This commit is contained in:
parent
a747aabe33
commit
10fd860837
|
@ -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
|
||||
|
|
|
@ -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}")
|
||||
|
|
Loading…
Reference in New Issue