Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save realyze/f2a53a4119f955ff63337af72ebbc5cf to your computer and use it in GitHub Desktop.

Select an option

Save realyze/f2a53a4119f955ff63337af72ebbc5cf to your computer and use it in GitHub Desktop.
#/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
chmod -R a+x .
@realyze
Copy link
Copy Markdown
Author

realyze commented Jul 25, 2018

This will set up git hooks that ensure you yarn when you ought to.

To install,

curl -L https://gist.githubusercontent.com/realyze/f2a53a4119f955ff63337af72ebbc5cf/raw/5892159f63e5c7e0248ca0e395abd86088f15494/yarn-composer-post-merge-and-checkout-hooks.sh | bash
git init 

Important notes:

  • Don't run this if you already have your own ~/.git-templates as this would overwrite them.
  • If you already have hooks configured in .git/hooks/, this won't change them so you'll want to manually add the section in EOL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment