Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save realyze/f2a53a4119f955ff63337af72ebbc5cf to your computer and use it in GitHub Desktop.
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" || true
}
# yarn all the things if yarn.lock has changed
check_run "web/yarn.lock" "cd web && yarn"
EOL
cp post-checkout ./post-merge && cp post-checkout ./post-fetch
chmod -R a+x .
@realyze
Copy link
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