Created
October 1, 2021 12:27
-
-
Save rogeruiz/1f523b878ca741b194e7f5c224310fb2 to your computer and use it in GitHub Desktop.
Check Changes using Git Post Merge hook
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 | |
# Check for things that are changed. A file or directory can be checked and a | |
# message is printed out for the user to perform an action on. Emoji use | |
# encouraged for the echo message. | |
# | |
# You may copy and paste the `if changed` statement below and modify the string | |
# that you'd like to grep for. Make sure you escape any back-ticks "\`" in your | |
# echo statements in order to include them in your message. | |
# | |
# It's recommended that you do not add commands besides `echo` statements in | |
# the if-statement block. This is because this command will run on every | |
# machine whenever that performs a `git pull` and this can cause arbitrary side | |
# effects. Also make sure you include a blank `echo` statement to allow for | |
# visual padding for the message, otherwise it can be difficult to visually | |
# discern the message from the previous output. | |
set -eo pipefail | |
function changed { | |
# The following command is getting the difference between what's currently in | |
# HEAD and comparing it with what's in the immediate prior value of the HEAD. | |
# | |
# This is not the same as "the previous commit" but rather "the previous | |
# value" before the `git pull`. | |
# | |
# It's then using `grep` to determine if the file is at the beginning of the | |
# line that the `--name-only` flag is outputting. | |
# | |
# For more infromation about this revision parameter, see the `git-rev-parse` | |
# documentation here: https://git-scm.com/docs/git-rev-parse#_specifying_revisions | |
git diff --name-only 'HEAD@{1}' HEAD | grep "^$1" > /dev/null 2>&1 | |
} | |
# Check for changes in the `migrations/` directory. | |
if changed 'migrations/'; then | |
echo | |
echo "🗄 The migrations/ directory has changed. You may want to run \`make db_dev_migrate\`." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment