Fix _update_repositories

The function failed if a folder at the top level was not a git repository
This commit is contained in:
Alexander Hess 2024-12-29 10:47:55 +01:00
parent b71714856f
commit cb0017e68a
Signed by: alexander
GPG key ID: 344EA5AB10D868E0

View file

@ -39,7 +39,32 @@ _remove_old_snaps() {
# Update local git repositories (mostly ~/repos)
function _fetch_repos {
local base_dir="$1"
local has_dirs=false
if [ "$(ls -A "$base_dir")" ]; then
for dir in "$base_dir"/*; do
if [ -d "$dir" ]; then
has_dirs=true
break
fi
done
fi
if [ "$has_dirs" = true ]; then
for dir in "$base_dir"/*; do
if [ -d "$dir" ]; then
if [ -d "$dir/.git" ]; then
echo "Fetching $dir"
(cd "$dir" && git fetch --all --prune)
fi
_fetch_repos "$dir"
fi
done
fi
}
_update_repositories() {
[ -d $REPOS ] || return
@ -52,10 +77,7 @@ _update_repositories() {
# if it cd's into a folder with a ".env" file
ZSH_DOTENV_FILE='.do_not_run_dotenv'
for dir in */; do
cd "$REPOS/$dir" && echo "Fetching $REPOS/$dir"
git fetch --all --prune
done
_fetch_repos "$REPOS"
ZSH_DOTENV_FILE='.env'