skate3recomp-multiplayer/tools/ci/init-submodules.sh
MiTHRAL babb887d4b ci: fix init-submodules empty-worktree check (ls -A counts .git)
A submodule with only a .git pointer looks non-empty to ls -A, so the
self-heal skipped every un-checked-out nested submodule. Check for real
worktree content instead (find excluding .git).
2026-08-27 11:53:54 -04:00

44 lines
No EOL
1.8 KiB
Bash
Executable file

#!/usr/bin/env bash
# Recursive submodule init for the rexglue SDK with self-healing for broken
# upstream pins.
#
# The rexglue fork pins several nested third-party submodules (imgui, ...) to
# commits their upstreams no longer carry, so a plain
# `git submodule update --init --recursive` aborts at the first broken pin
# and leaves every later nested submodule empty (a fresh clone cannot build).
# For each nested submodule still left empty, this script fetches its origin
# and checks out the default-branch tip, which is enough to build.
#
# Run from the repository root after `git submodule update --init` (top
# level). No-op when everything initialized fine.
set -uo pipefail
SDK="third_party/rexglue-sdk"
if [ ! -e "$SDK/.git" ]; then
echo "init-submodules: $SDK is not initialized (run git submodule update --init first)"
exit 1
fi
(
cd "$SDK"
git submodule update --init --recursive --jobs 4 >/tmp/ghost_sub_init.log 2>&1 || true
while IFS= read -r path; do
# A submodule needs self-healing when it has no .git, or its worktree
# has no files other than the .git pointer (ls -A counts .git and would
# wrongly treat an un-checked-out submodule as initialized).
if [ ! -e "$path/.git" ] ||
[ -z "$(find "$path" -mindepth 1 -maxdepth 1 ! -name '.git' -print -quit 2>/dev/null)" ]; then
echo "init-submodules: self-healing empty submodule $path"
if (cd "$path" && git fetch --depth 1 origin >/dev/null 2>&1 &&
git checkout -q FETCH_HEAD >/dev/null 2>&1); then
echo " ok: $path -> $(git -C "$path" rev-parse --short HEAD)"
else
echo " WARN: could not self-heal $path (build may fail on this dependency)"
fi
fi
done < <(git config --file .gitmodules --get-regexp '^submodule\..*\.path$' | awk '{print $2}')
)
exit 0