Commit 2ee36fdb authored by Remi Oudin's avatar Remi Oudin

[check_repos] Le script gère les submodules, et fetch une première fois si nécessaire

parent 15be1358
......@@ -8,13 +8,13 @@ export LANG=C
export LC_ALL=C
# Paths des dépôts à surveiller
GIT_REPOS="/usr/scripts /usr/scripts/lc_ldap"
GIT_REPOS="/home/oudin/scripts /home/oudin/scripts/lc_ldap"
# Intervalle entre deux fetchs
PERIOD=5
check_repo () {
echo "vérification de $1"
echo "Vérification de $1"
cd $1
( git status | grep "# Your branch" -q ) && {
echo "...et dépôt pas à jour"
......@@ -24,29 +24,63 @@ check_repo () {
fetch_updates () {
cd $1
if [ ! -f ".git/FETCH_HEAD" ]; then
echo "Initial fetching of the repo"
git fetch
fi
if test ! "`find .git/FETCH_HEAD -mmin +$PERIOD`"; then
return
fi
umask 002
echo "fetching $1"
git fetch origin > /dev/null
if [ $hasmodules -eq 0 ]; then
echo "Fetching recursively"
git fetch --recurse-submodules origin > /dev/null
else
git fetch origin > /dev/null
fi
}
try_ff () {
cd $1
if git status | grep "^Your branch is behind.*can be fast-forwarded.$" -q; then
echo "Fast forward..."
git pull || exit 12
if [ $hasmodules -eq 0 ]; then
git pull --recurse-submodules origin master || exit 12
else
git pull || exit 12
fi
else
echo "Nothing to fast forward"
fi
}
has_submodules () {
cd $1
if (ls -al | grep ".gitmodules"); then
subdirs="$(cat .gitmodules | grep path | cut -d= -f2-)"
for subdir in $subdirs; do
cd $subdir
if [ `ls -lA | wc -l` -eq 1 ]; then
echo "Initializing submodule"
git submodule init
git submodule update
fi
return 0
done
fi
return 1
}
# Et on check que les repos sont ok
for dir in $GIT_REPOS; do
fetch_updates $dir
check_repo $dir
try_ff $dir
has_submodules $dir
hasmodules=$?
fetch_updates $dir
check_repo $dir
try_ff $dir
done
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment