git-utils/git-pullall
Alex A. Naanou cf6b94b6bf made pull fallback optional...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2023-05-11 21:51:26 +03:00

90 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# config...
#
#FALLBACK_TO_PULL=yes
#
while true ; do
case $1 in
-h|--help)
echo "Usage: $(basename "$0") [OPTIONS] [PATH]"
echo
echo "Pull all repositories in PATH."
echo
echo "Options:"
echo " -h --help - print this message and exit"
echo " -r --recursive - pull directories recursively"
echo " -l --list - print found repositories and exit"
echo
exit
;;
-r|--recursive)
RECURSIVE=1
shift
continue
;;
-l|--list)
LIST=1
shift
continue
;;
-*|--*)
echo "Error: unknown option: \"$1\"" >&2
exit
;;
*)
TARGET_PATH=$1
break
;;
esac
done
FALLBACK_TO_PULL=${FALLBACK_TO_PULL:=yes}
TARGET_PATH=${TARGET_PATH:=.}
cd "$TARGET_PATH"
if [ $RECURSIVE ] ; then
DIRS=($(find . -name .git | sort))
else
DIRS=(./*/.git)
fi
# inside a repo...
if [ $FALLBACK_TO_PULL = "yes" ] && [ -d ./.git ] ; then
echo "running inside a repository, falling back to vanilla pull..."
git pull
exit 0
fi
# no matches...
if [[ $DIRS =~ \* ]] ; then
echo "no repos found." >&2
exit 1
fi
# do the update...
wd=$(pwd)
for dir in ${DIRS[@]} ; do
dir=${dir%.git}
echo $dir
if [ $LIST ] ; then
continue
fi
cd "$dir"
git pull
cd "$wd"
echo
done
# vim:set sw=4 ts=4 :