I'm writing a Bash script to output info about references in multiple Git repositories. So far it looks like this -
# paths that have Git repos
paths[0]="./playground"
paths[1]="./sandbox"
# reference objects common to all repos
references[0]="main"
references[1]="v1"
references[2]="v2"
references[3]="v3"
echo "Object type of reference in each repository -"
for reference in "${references[@]}"
do
echo "~~~ $reference ~~~"
for path in "${paths[@]}"
do
OBJECT_TYPE=$(git -C "$path" cat-file -t "$reference")
if [ "$OBJECT_TYPE" = "tag" ]; then
prefix="annotated"
#else
#TODO: implement logic for lightweight tags, branches
fi
echo "$prefix $OBJECT_TYPE $path"
done
echo
done
The annotated tag part is working correctly. However, the $OBJECT_TYPE for branches and lightweight tags are both "commit", which is as expected, but not helpful for identifying which references are branches and which are lightweight tags. How can they be distinguished?