Skip to content

Instantly share code, notes, and snippets.

@machta
Created January 19, 2019 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save machta/e5ba03be62f34e8bbecaf22aaefee8fc to your computer and use it in GitHub Desktop.
Save machta/e5ba03be62f34e8bbecaf22aaefee8fc to your computer and use it in GitHub Desktop.
Checks that this repository and all of its submodules point to the tip of a certain BRANCH
#!/bin/bash
#
# Usage ./git-check-versions.sh BRANCH
#
# Checks that this repository and all of its submodules point to the tip of
# a certain BRANCH.
BRANCH=$1
check() {
cd $2
BRANCH_HASH=`git log --pretty=format:"%H" $BRANCH -- 2>/dev/null | head -1`
[ "$BRANCH_HASH" = "$1" ] ||
echo "$2 doesn't point to the tip of branch $BRANCH"
cd - >/dev/null
}
# Check this repo
check `git log --pretty=format:"%H" | head -1` .
# Also check submodules
git submodule status --recursive | while read line ; do
SUB_HASH=`echo $line | awk '{print $1}'`
SUB_PATH=`echo $line | awk '{print $2}'`
check $SUB_HASH $SUB_PATH
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment