core-lightning/tools/refresh-submodules.sh
Rusty Russell 76dd1577bd external: fix submodule handling for parallel builds, submodule URL changes.
If we change an upstream URL, all submodules break.  Users would need
to run 'git submodule sync'.  Note that the libbacktrace fix was merged
upstream so this is no longer necessary, but it's good for future changes.

Also, stress-testing reveals that git submodule fails locking
'.git/config' when run in paralell.  It also segfaults and other
problems.

This is my final attempt to fix submodules; I've wasted far too many
days on obscure problems it creates: I've already lost one copy of my
repo to apparently unfixable submodule preoblems.  The next "fix" will
be to simply import the source code so it works properly.

Reported-by: @jsarenik
Fixes: #1543
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-06-08 17:56:01 +02:00

31 lines
721 B
Bash
Executable File

#! /bin/sh
if [ $# = 0 ]; then
echo "Usage: $0 <submoduledir1>..." >&2
exit 1
fi
# git submodule can't run in parallel. Really.
echo $$ > .refresh-submodules.$$
if ! mv -n .refresh-submodules.$$ .refresh-submodules; then
rm -f .refresh-submodules.$$
exit 0
fi
trap "rm -f .refresh-submodules" EXIT
# Be a little careful here, since we do rm -rf!
for m in "$@"; do
if ! grep -q "path = $m\$" .gitmodules; then
echo "$m is not a submodule!" >&2
exit 1
fi
done
# git submodule can segfault. Really.
if [ "$(git submodule status "$@" | grep -c '^ ')" != $# ]; then
echo Reinitializing submodules "$@" ...
git submodule sync "$@"
rm -rf "$@"
git submodule update --init "$@"
fi