Skip to content

Instantly share code, notes, and snippets.

@PandaWhisperer
Created October 2, 2018 20:14
Show Gist options
  • Save PandaWhisperer/0ccf0ddf5eb30291f9b055cf0db77791 to your computer and use it in GitHub Desktop.
Save PandaWhisperer/0ccf0ddf5eb30291f9b055cf0db77791 to your computer and use it in GitHub Desktop.
#/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
}
# run `yarn` if package.json changed
check_run package.json "yarn"
# run `yarn` if yarn.lock changed
check_run yarn.lock "yarn"
# run `bundle install` if Gemfile.lock changed
check_run Gemfile.lock "bundle install"
# run `yarn build:client` if any JS code was updated
check_run app/javascript "yarn build:client"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment