Skip to content

Instantly share code, notes, and snippets.

@mrtry
Created May 19, 2021 12:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrtry/6a624966e536299e9ca9157ed89cad7d to your computer and use it in GitHub Desktop.
Save mrtry/6a624966e536299e9ca9157ed89cad7d to your computer and use it in GitHub Desktop.
run `npm install` when update package.json
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
prevHEAD=$1
nextHEAD=$2
prevPackageHash=$(git log --format="%C(auto)%h%Creset" -n 1 $prevHEAD -- package.json | cat)
nextPackageHash=$(git log --format="%C(auto)%h%Creset" -n 1 $nextHEAD -- package.json | cat)
if [ "$prevPackageHash" != "$nextPackageHash" ]; then
npm i
else
echo "post-checkout: do nothing"
fi
@mrtry
Copy link
Author

mrtry commented May 21, 2021

git diff —exit-code —quiet で差分あるかを調べれるが、帰ってきたexit-codeでhookが終了してしまうので、git logからのhashで比較してる

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