git-filter-repo/compare-repos

97 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
if [[ $# < 2 || $# > 3 ]]; then
echo "Syntax:"
echo " $0 REPO1 REPO2 [--summary]"
exit 1
fi
repo1=$1
repo2=$2
detail=1
if [ $# == 3 ]; then
if [ $3 != "--summary" ]; then
echo "Unrecognized argument: $3"
exit 1
fi
detail=
fi
if ( ! (cd $repo1 && git rev-parse --git-dir > /dev/null) ); then
echo "$repo1 is not a directory or does not have a git repository!"
exit 1
fi
if ( ! (cd $repo2 && git rev-parse --git-dir > /dev/null) ); then
echo "$repo2 is not a directory or does not have a git repository!"
exit 1
fi
tempfile=$(mktemp)
#
# Compare branches for identicalness
#
diff -u <(cd $repo1 && git show-ref -h --heads --tags) <(cd $repo2 && git show-ref -h --heads --tags) > $tempfile
if [ $? != 0 ]; then
echo -n "Branches & tags do not match"
if test $detail; then
echo "; differences:"
cat $tempfile
else
echo "."
fi
else
echo "* Branches and tags match exactly"
exit 0
fi
#
# Compare branch names
#
diff -u <(cd $repo1 && git for-each-ref --format="%(refname)" | grep refs/heads/) <(cd $repo2 && git for-each-ref --format="%(refname)" | grep refs/heads/) > $tempfile
if [ $? != 0 ]; then
echo -n "Branch names do not match"
if test $detail; then
echo "; differences:"
cat $tempfile
else
echo "."
fi
else
echo "* Branch names match"
fi
#
# Compare trees of branches
#
diff -u <(cd $repo1 && git rev-parse $(git for-each-ref --format="%(refname)" | grep refs/heads/ | sed -e s/$/^{tree}/)) <(cd $repo2 && git rev-parse $(git for-each-ref --format="%(refname)" | grep refs/heads/ | sed -e s/$/^{tree}/)) > $tempfile
if [ $? != 0 ]; then
echo -n "Trees of branches do not match"
if test $detail; then
echo "; differences:"
cat $tempfile
else
echo "."
fi
else
echo "* Trees of branches match"
fi
#
# Compare number of commits on each branch
#
diff -u <(cd $repo1 && for i in $(git for-each-ref --format="%(refname)" | grep refs/heads/); do count=$(git rev-list $i | wc -l); printf "%5d %s\n" $count $i; done) <(cd $repo2 && for i in $(git for-each-ref --format="%(refname)" | grep refs/heads/); do count=$(git rev-list $i | wc -l); printf "%5d %s\n" $count $i; done) > $tempfile
if [ $? != 0 ]; then
echo -n "Branch commit counts do not match"
if test $detail; then
echo "; differences:"
cat $tempfile
else
echo "."
fi
else
echo "* Branch commit counts match"
fi
rm $tempfile