Skip to content

Instantly share code, notes, and snippets.

@nick87720z
Last active June 22, 2021 19:56
Show Gist options
  • Save nick87720z/83d1f85ae5d3b98cbb9728d39f72cce2 to your computer and use it in GitHub Desktop.
Save nick87720z/83d1f85ae5d3b98cbb9728d39f72cce2 to your computer and use it in GitHub Desktop.
#!/bin/bash
# exec depends: git, sed, sort
# commit archive url formats:
# repo.or.cz: ${GIT_REPO_URI}/snapshot/${COMMIT}.tar.gz
# github: ${GIT_REPO_URI}/archive/${COMMIT}.tar.gz
# gitlab: ${GIT_REPO_URI}/-/archive/${COMMIT}/${PROJECT}-${COMMIT}.tar.bz2
# git.tuxfamily.org,
# savannah/cgit: ${GIT_REPO_URI}/snapshot/${PROJECT}-${COMMIT}.tar.gz
git submodule foreach --recursive '
printf "%s\n" "$sha1 $displaypath $(
url=$( git remote get-url origin )
url="${url%\/}"
IFS="/" read host tail <<< "${url/*:\/\//}"
name="${tail/*\//}"
name="${name%.git}"
filename="${name}-${sha1}"
url="${url/git:/https:}"
case "${host}" in
repo.or.cz )
printf "%s" "${filename}.tar.gz ${url}/snapshot/${sha1}.tar.gz" ;;
*github.com )
printf "%s" "${filename}.tar.gz ${url}/archive/${sha1}.tar.gz" ;;
*gitlab.com )
printf "%s" "${filename}.tar.bz2 ${url}/-/archive/${sha1}/${name}-${sha1}.tar.bz2" ;;
git.savannah.* )
url=${url/${host}\/r\//${host}\/cgit\/}
url=${url/${host}\/git\//${host}\/cgit\/}
printf "%s" "${filename}.tar.gz ${url}/snapshot/${name}-${sha1}.tar.gz" ;;
git.tuxfamily.org )
printf "%s" "${filename}.tar.gz ${url}/snapshot/${name}-${sha1}.tar.gz" ;;
* )
printf "%s" "${filename} ${url} FIXME: Unsupported git host" ;;
esac
)"
' | sed -n '2~2p' | sort -k2,2
missing="$( git submodule status --recursive | sed -n '/^-/s/-[[:alnum:]]*\ /- /p' )"
if [ "${missing}" ]; then
printf "\n%s\n" \
"These submodules can't be described, because are not downloaded:" \
"$missing" \
"Run 'git submodule update' to update them."
fi >&2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment