Last active
March 11, 2016 04:27
-
-
Save twig/927b638519db39149475 to your computer and use it in GitHub Desktop.
Git hook to display notification on post-merge if certain files changed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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