Skip to content

Instantly share code, notes, and snippets.

@twig
Last active March 11, 2016 04:27
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 twig/927b638519db39149475 to your computer and use it in GitHub Desktop.
Save twig/927b638519db39149475 to your computer and use it in GitHub Desktop.
Git hook to display notification on post-merge if certain files changed
#!/usr/bin/env bash
#
# Save this to yourproject/.git/hooks/post-merge
#
# After a successful merge, check if bower.json, package.json
# or requirements has changed and notify the user to take
# appropriate actions.
#
# https://github.com/git/git/blob/master/Documentation/githooks.txt#L167
# This hook cannot affect the outcome of 'git merge' and is not executed,
# if the merge failed due to conflicts.
#
# Based off https://gist.github.com/sindresorhus/7996717
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
# This method checks and notifies
check_warn() {
echo "$changed_files" | grep --quiet "$1" && echo -e "\e[1;31m$1 changed: Please run:\e[39m $2\e[0m"
}
# This method checks and runs automatically
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
}
check_run package.json "npm install"
check_run bower.json "bower update"
check_warn requirements.txt "pip install -r requirements.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment