Skip to content

Instantly share code, notes, and snippets.

@benlemasurier
Created March 7, 2012 22:11
Show Gist options
  • Save benlemasurier/1996573 to your computer and use it in GitHub Desktop.
Save benlemasurier/1996573 to your computer and use it in GitHub Desktop.
pre-commit
#!/bin/bash
# Check whether any submodule is about to be updated with the
# commit. Ask the user for confirmation.
echo "Checking if any submodules are being updated..."
ROOT_DIR=$(git rev-parse --show-cdup)
SUBMODULES=$(grep path ${ROOT_DIR}.gitmodules | sed 's/^.*path = //')
# submodules that have been modified
MOD_SUBMODULES=$(git diff --cached --name-only | grep -F "$SUBMODULES")
# If no modified submodules, exit with status code 0, else prompt the
# user and exit accordingly
if [[ -n "$MOD_SUBMODULES" ]]; then
echo "The following modified submodules are about to be committed:"
echo "$MOD_SUBMODULES"
echo -n "Continue with commit? [yN] "
read -n 1 reply </dev/tty
echo
if [[ "$reply" == "y" || "$reply" == "Y" ]]; then
exit 0
else
echo "Aborted commit."
exit 1
fi
else
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment