Skip to content

Instantly share code, notes, and snippets.

@ThisIsMissEm
Created October 8, 2019 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThisIsMissEm/eeb9b3e0fb2e8b211a0bfb1641d9b876 to your computer and use it in GitHub Desktop.
Save ThisIsMissEm/eeb9b3e0fb2e8b211a0bfb1641d9b876 to your computer and use it in GitHub Desktop.
#! /usr/bin/env node
/**
* This file does not use typescript as it's run before you've necessarily run `yarn install`
* As such, we can only use built-in modules here.
*/
function main() {
let [
// Arguments from the githook: https://git-scm.com/docs/githooks#_post_checkout
prevHead,
head,
isFileCheckout
] = process.env.HUSKY_GIT_PARAMS.split(' ', 3);
// we're doing `git checkout foo.js` so don't run:
if (isFileCheckout === '0') {
return;
}
const diffArgs = [prevHead, head, '--', 'package.json'];
const args = ['diff', '--exit-code', '--quiet', ...diffArgs];
const result = require('child_process').spawnSync('git', args, {
encoding: 'utf8'
});
if (result.status === 1) {
console.log(`
⚠️ package.json was changed! You may wish to run:
$ yarn install
You can see the changes with:
$ git diff ${diffArgs.join(' ')}
`);
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment