1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#! /usr/bin/env bash
#
# Recursively check outs the most recent version of all submodules on a given
# branch, and commits the updates to the parents.
branch=$1
if [ "$branch" == "" ]; then
echo "usage: `basename $0` <branch>"
exit 1
fi
function update_module {
local cwd=$1
local i
local modules=""
cd $cwd
# Note we don't use --recursive here, as we want to do a depth-first
# search so that we update childrens first.
for i in `git submodule foreach -q 'echo $path'`; do
# See if repository has a branch of the given name. Otherwise leave it alone.
( cd $i && git show-ref --verify --quiet refs/heads/$branch ) || continue
modules="$modules $i"
echo "--- Checking out $branch of `basename $i`"
cd $i
git checkout -q $branch || exit 1
update_module $cwd/$i
cd $cwd
done
if [ "$modules" != "" ]; then
echo "+++ Commiting updates to `basename $cwd`"
git commit -m 'Updating submodule(s).
[nomail]' --only $modules
fi
}
update_module `pwd`
|