Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get the latest tag for every git repo in a directory
#!/usr/bin/env bash
function is_git_repo() {
ls .git &> /dev/null
}
function get_latest_tag_for_repo() {
pushd ${1} &> /dev/null
is_git_repo
local is_git_repo=$?
if [[ ${is_git_repo} != 0 ]]; then
popd &> /dev/null
return 0
fi
echo "$(basename ${1}) $(git describe --tags --always)"
popd &> /dev/null
}
export -f get_latest_tag_for_repo is_git_repo
REPOS_PATH="${REPOS_PATH:=./}"
# Check if GNU parallell is installed
command -v parallel &> /dev/null
HAS_GNU_PARALLEL_RC=$?
# Pull all repos under the directory simultaneously
if [[ ${HAS_GNU_PARALLEL_RC} == 0 ]]; then
ls -d ${REPOS_PATH}/*/ | parallel get_latest_tag_for_repo
else
for dir in $(ls -d ${REPOS_PATH}/*/); do
(get_latest_tag_for_repo ${dir}) &
done
# Wait for all jobs to complete
while [[ ! -z $(jobs -r) ]]; do
sleep 1
done
fi
echo "Done."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.