Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions easybuild/scripts/get-submodule-info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Flamefire Please include a license header, which also mentions author

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


echo "Print information on all submodules for the git repository in $PWD"
echo
echo "Format: '<name>': ('<owner>/<name>', '<commit>', '<path>'),"
echo

function print_submodules {
local base_path=$1
git -C "$base_path" submodule status | while read -r line; do
# Example line: " 3a6b7dc libs/foo (heads/main)"
commit=$(echo "$line" | awk '{print $1}')
path=$(echo "$line" | awk '{print $2}')

if [[ -z $base_path ]]; then
sub_folder=$path
else
sub_folder=$base_path/$path
fi

# Extract owner/repo from URL
url=$(git config --file "${base_path:-$PWD}/.gitmodules" --get "submodule.$path.url")
repo_slug=$(echo "$url" | sed -E 's#.*[:/]([^/:]+/[^/.]+)(\.git)?$#\1#')

name=$(basename "$path")
short_commit=$(git -C "$sub_folder" rev-parse --short "$commit" 2>/dev/null || echo "$commit")

printf "'%s': ('%s', '%s', '%s'),\n" "$name" "$repo_slug" "$short_commit" "$sub_folder"
print_submodules "$sub_folder"
done
}

print_submodules "" | sort