Skip to content

Instantly share code, notes, and snippets.

@uncreative
Forked from betorobson/post-checkout
Last active November 11, 2017 06:10
Show Gist options
  • Save uncreative/2425c534b6b20703af2cc361b4a93fb9 to your computer and use it in GitHub Desktop.
Save uncreative/2425c534b6b20703af2cc361b4a93fb9 to your computer and use it in GitHub Desktop.
git hook to run a command after `git pull` and `git checkout` if a specified file was change for example, package.json or bower.json

1. Copy theses files into your hooks folder

git clone [email protected]:2425c534b6b20703af2cc361b4a93fb9.git githooks
GIT_HOOK_DIR="${PWD}/githooks"
echo "export GIT_HOOK_DIR=${GIT_HOOK_DIR}" >> ~/.bashrc
echo "${GIT_HOOK_DIR}/post-merge" >> .git/hooks/post-merge
echo "${GIT_HOOK_DIR}/post-checkout" >> .git/hooks/post-checkout

Thanks to these guys:

#!/usr/bin/env bash
changed_files="$(git diff-tree -r --name-only --no-commit-id $1 $2)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
}
post_checkout(){
make_reqs
echo "${GIT_HOOK_DIR}/post-checkout" >> .git/hooks/post-checkout
}
check_run base-private.txt post_checkout
check_run base.txt post_checkout
check_run dev-private.txt post_checkout
check_run dev.txt post_checkout
exit 0;
#!/usr/bin/env bash
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
}
post_merge(){
make_reqs
echo "${GIT_HOOK_DIR}/post-merge" >> .git/hooks/post-merge
}
check_run base-private.txt post_merge
check_run base.txt post_merge
check_run dev-private.txt post_merge
check_run dev.txt post_merge
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment