git-utils/bin/git-pullall
Alex A. Naanou 3f8484b12a added docs...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2026-11-07 17:26:36 +03:00

84 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
SKIP_FILE=${SKIP_FILE:-.pullall-skip}
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"
if ! [ -z $SKIP_FILE ] ; then
echo
echo "If $SKIP_FILE is present in the repository root directry"
echo "the repository will not get pulled."
#echo "To disable this behavior set \$SKIP_FILE to empty, e.g:"
#echo " SKIP_FILE= git pullall -r"
fi
echo
exit
;;
-r|--recursive)
RECURSIVE=-r
shift
continue
;;
-*|--*)
echo "Error: unknown option: \"$1\"" >&2
exit
;;
*)
TARGET_PATH=$1
break
;;
esac
done
TARGET_PATH=${TARGET_PATH:=.}
cd "$TARGET_PATH"
IFS=$'\n'
DIRS=($(git listall -d ${RECURSIVE}))
# inside a repo...
if [ -d ./.git ] ; then
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 ! [ -z $SKIP_FILE ] \
&& [ -e "$dir/$SKIP_FILE" ] ; then
echo "skipping..."
echo
continue
fi
cd "$dir"
git pull
cd "$wd"
echo
done
# vim:set sw=4 ts=4 :