Last active
February 11, 2019 09:34
-
-
Save drAlberT/606e0698cb00805efa3a6f1c3ee97a3e to your computer and use it in GitHub Desktop.
Automatically update git sub-modules
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 | |
# | |
# Quick script to automatically update git submodules on checkout. | |
# Save it in the repo `.git/hooks` dir and make it executable | |
#echo "post-checkout hook: '$1' '$2' '$3'" | |
oldRef=$1 | |
newRef=$2 | |
# Exit early if the local branch is behind the remote | |
LOCAL=$(git rev-parse @) | |
REMOTE=$(git rev-parse @{u} 2> /dev/null) | |
BASE=$(git merge-base @ @{u} 2> /dev/null) | |
if [[ "$LOCAL" != "$REMOTE" && "$LOCAL" = "$BASE" ]]; then | |
exit 0 | |
fi | |
function isChanged { | |
git diff --name-only $oldRef $newRef | grep "^$1\$" >/dev/null 2>&1 | |
} | |
if isChanged '.gitmodules'; then | |
echo "Change detected to '.gitmodules', updating git submodules." | |
git submodule update --init --force # --recursive | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment