Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#/bin/bash
#
# Assumes you have run 'github_get_all.sh' to get the latest git repos for your org
#
# Note:This script will ONLY work reliably if you have run 'github_get_all.sh on an empty
# directory, so that all repos are freashly cloned and clean
#
# Iterate over all the github repos under the cwd, for each reports if
# branch1 is behind branch2
#
# eg: To see if develop is behind master:
#
# github_check_branch.sh MyOrg master develop
#
# Outputs to ~github_check_branch.log logfile in the current dir.
#
# See https://github.com/davidoram/ght
ght repos -o "$1" > all_repos.txt
branch1=$2
branch2=$3
logfile=$(pwd)/~github_check_branch.log
echo "> Started. Checking if branch '${branch1}' is behind '${branch2}'" > ${logfile}
while read org_repo; do
if [[ $org_repo =~ (.*)/(.*) ]]; then
org=${BASH_REMATCH[1]}
repo=${BASH_REMATCH[2]}
if [[ -d "${repo}" ]]; then
pushd "${repo}"
diffurl="https://github.com/${org_repo}/compare/${branch1}...${branch2}"
# Check branch1 exists
git checkout "${branch1}"
if [[ $? -eq 0 ]]; then
# Check branch2 exists
git checkout "${branch2}"
if [[ $? -eq 0 ]]; then
# See https://stackoverflow.com/questions/20433867/git-ahead-behind-info-between-master-and-branch
behind=$( git rev-list --right-only --count ${branch1}...${branch2} )
if [[ $behind -eq 0 ]]; then
echo "OK ${org_repo} branch '${branch1}' is behind branch '${branch2}' by ${behind} commits. ${diffurl}" >> ${logfile}
else
echo "BEHIND ${org_repo} branch '${branch1}' is behind branch '${branch2}' by ${behind} commits. ${diffurl}" >> ${logfile}
fi
else
echo "MISSING ${org_repo} doesnt have branch '${branch2}'. ${diffurl}" >> ${logfile}
fi
else
echo "MISSING ${org_repo} doesnt have branch '${branch1}'. ${diffurl}" >> ${logfile}
fi
popd
else
echo "${org_repo} ERROR: Missing repo " >> ${logfile}
fi
fi
done <all_repos.txt
echo '> Finished' >> ${logfile}
echo "See ${logfile}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment