sysconfig/git-pull-recursive.sh
2022-10-17 11:40:49 +08:00

49 lines
1.2 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
if [ $1 ]
then
FONPATH=$1
elif [ -d /faronear ]
then
FONPATH=/faronear
elif [ -d ~/faronear ]
then
FONPATH=~/faronear
elif [ -d /mnt/d/faronear ]
then
FONPATH=/mnt/d/faronear
else
echo "=== Enter [faronear root path] or leave blank for default to [.]"
read -p ">>> " FONPATH
echo ""
if [ ! $FONPATH ]
then
FONPATH=.
fi
fi
if [ ! -d $FONPATH ]
then
echo "*** [$FONPATH] not exist! Exit now. ***"
exit
fi
pushd $FONPATH
echo "*** FONPATH = [`pwd`] ***"
echo ""
# for org in `ls -F | grep '/$' | grep -v '~'` ## 首先过滤出所有子目录,然后过滤出所有不含 ~ 的子目录。注意 for ??? in `ls ???` 是按照空行以及空格进行分割的因此最后筛选出的目录名不能含有空格否则就被分割成多个了。for ??? in * 是分割成一个个目录名的,即使目录名含有空格。)
# ls -F | grep '/$' | grep -v '=' | while read org ## 换用这种方法,可以成功过滤出含有空格的完整目录名
find . -mindepth 2 -maxdepth 3 -type d -name '?*.git' | grep -v 'node_modules' | while read repo
do
if [ -d "$repo/.git" ]
then
echo "---- git pulling [`pwd`/$repo] ----"
pushd "$repo"
git pull --all
echo ""
popd
fi
done
popd