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