#!/bin/bash
#
# Execute this from the top-level fully checked out project.
# You can use /cvmfs/atlas-online-nightlies.cern.ch/tdaq/nightlies/tdaq-nightly for this.
#
# Every printed out package should be checked since the version in the first branch
# is not an ancestor of the version in the second branch.
# This can be on purpose (e.g. branch for old release to fix a bug), or an oversight
# so it has to be checked manually.
#
[ $# -lt 1 ] && { echo "$0 <branch1> <branch2>"; exit 1; }
first=origin/$1
if [ -n "$2" ]; then
    second=origin/$2
fi

for pkg in $(git submodule status | awk '{print $2;}')
do
    commits=$(git diff $first $second -- ${pkg} | grep '^.Subproject' | sed 's;^.*commit ;;' | tr '\n' ' ')
    [ -z "${commits}" ] && continue
    # echo "Comparing ${pkg} ${commits}"
    c1=$(echo $commits | cut -f1 -d' ')
    c2=$(echo $commits | cut -f2 -d' ')
    (cd $pkg; git merge-base --is-ancestor ${commits} || printf "%-20s%-40s%-40s | %-40s%-s\n" ${pkg} $(git describe --tags --always $c1) $(git rev-parse $c1) $(git describe --tags $c2) $(git rev-parse $c2))
done
