Last active
July 25, 2018 00:14
-
-
Save martinwheeler/f03147e14f9d67eb4fd0a3437cdfd3e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin/env bash | |
git config --global init.templatedir '~/.git-templates' && \ | |
mkdir -p ~/.git-templates/hooks && \ | |
cd ~/.git-templates/hooks | |
cat >post-checkout <<'EOL' | |
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)" | |
check_run() { | |
echo "$changed_files" | grep -E --quiet "$1" && eval "$2" | |
} | |
# `npm install` and `npm prune` if the `package.json` file gets changed | |
# to update all the nodejs ( grunt ) dependencies deleting the unused packages (not listed into the `package.json` file) | |
check_run package.json "yarn install" | |
# `composer install` if the `composer.json` file gets changed | |
# to update all the php dependencies | |
check_run composer "composer install" | |
EOL | |
cp post-checkout ./post-merge && cp post-checkout ./post-fetch | |
chmod -R a+x . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yarn & Composer Git Hooks
This snippet creates two simple post git hooks that will make your life as a web developer much easier.
After every 'merge' (runs on git pull), 'checkout' & 'fetch' the snippet will check the changes from your previous branch to the current one for your
package.json
andcomposer
file. If there are changes it will then runyarn install
and/orcomposer install
for you.Setup
curl -L https://gist.githubusercontent.com/martinwheeler/f03147e14f9d67eb4fd0a3437cdfd3e0/raw/624c10f93a8c909dd19e82a97a453f90ddad157d/yarn-composer-post-merge-and-checkout-hooks.sh | bash
git init
inside your local repoNote
The
git init
will re-initialise the local hooks from the global.git-templates
folder but it won't override any hooks that are already created with the same name