docksal / blt-docksal

Acquia BLT Docksal integration
4 stars 5 forks source link

Support for git hooks #6

Open christianwiedemann opened 3 years ago

christianwiedemann commented 3 years ago

Hi again,

BLT uses git hooks to validate templates / php etc. These hooks are using PHP. So it would be great to pass the scripts to docksal CLI container. For example the pre commit hook could work like this:

!/usr/bin/env bash


ROOT_DIR="$(pwd)/"
LIST=$( git diff --name-only --cached --diff-filter=ACM )

echo "Executing .git/hooks/pre-commit..."
git diff-index --quiet HEAD -- || echo "Untracked files are present, this may impact the validity of pre-commit checks."
fin exec /var/www/vendor/bin/blt internal:git-hook:execute:pre-commit "${LIST}"

# Return the status of the last run command.
exit $?

I could open a pull with these updated scripts and an updated local.blt.setting which points to the script:

git:
  hooks:
    pre-commit: ${repo.root}/vendor/docksal/docksal-blt/git-hooks
    pre-push: ${repo.root}/vendor/docksal/docksal-blt/git-hooks
    commit-msg: ${repo.root}/vendor/docksal/docksal-blt/git-hooks

What do you think? And thanks for your work.

shelane commented 2 years ago

@christianwiedemann This sounds like a great idea. I'd love to give it a try. Do you still want to do a PR for it?