Skip to content

Instantly share code, notes, and snippets.

@simion
Last active August 29, 2015 14:13
Show Gist options
  • Save simion/3fa70d4327f5744c5ab7 to your computer and use it in GitHub Desktop.
Save simion/3fa70d4327f5744c5ab7 to your computer and use it in GitHub Desktop.
Git hook that watches for a specific file being changed (when merging). It gives a red warning when changes are detected.
#!/bin/bash
set -eu
# place the content of this file in .git/hooks/post-merge and make it executable
# change the following variable acording to your needs.
# You can set either a file path, or a folder path (in this case, all files in that folder are being watched)
watch_path=pydpf/settings
git diff "HEAD@{1}" --name-only | grep $watch_path 2>&1 > /dev/null
CHANGED=$?
if [ $CHANGED ]; then
echo
tput setaf 1
echo -e "DETECTED CHANGES IN $watch_path !!!"
tput sgr0
echo "Changed files:"
tput setaf 6
git diff "HEAD@{1}" --name-only | grep $watch_path
tput sgr0
echo
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment