build-redbear.sh: enforce submodule/<name> branch on every fork worktree

Per local/AGENTS.md § "BRANCH AND SUBMODULE POLICY (ABSOLUTE)":\neach Red Bear fork worktree must be on the canonical\n"submodule/<name>" branch. Until now, the build system had NO\ncode enforcing this — drift was caught only by operator discipline\n(Round-21 hand-normalized 6 of 9 forks).\n\nAdd a new redbear_check_fork_branches() function called as a peer of\nthe existing dirty-source gate. It iterates REDBEAR_FORK_SOURCES,\nreads each fork worktree's current branch via 'git branch\n--show-current', and compares to 'submodule/<label>'. On mismatch\nthe build aborts with a clear error message and a documented fix\nrecipe. Escape hatch: REDBEAR_ALLOW_WRONG_BRANCH=1.
This commit is contained in:
2026-07-14 13:00:52 +09:00
parent 441aba3d32
commit e462d576f4
+48
View File
@@ -53,6 +53,48 @@ redbear_is_fork_dirty() {
return 1
}
# Per AGENTS.md § "BRANCH AND SUBMODULE POLICY (ABSOLUTE)": each Red Bear
# fork worktree MUST be checked out on the canonical "submodule/<name>"
# branch. This gate prevents drift from the canonical branch topology.
redbear_check_fork_branches() {
local err=0
local wrong=()
for entry in "${REDBEAR_FORK_SOURCES[@]}"; do
local label="${entry%%:*}"
local dir="${entry#*:}"
[ -d "$dir" ] || continue
local cur_branch
cur_branch=$(git -C "$dir" branch --show-current 2>/dev/null) || continue
local expected="submodule/${label}"
if [ "$cur_branch" != "$expected" ]; then
wrong+=("$label (got '$cur_branch', expected '$expected')")
err=1
fi
done
if [ "$err" != "0" ]; then
echo "========================================" >&2
echo " REFUSING TO BUILD — FORKS NOT ON CANONICAL BRANCHES" >&2
echo "========================================" >&2
echo "" >&2
echo "Per AGENTS.md § 'BRANCH AND SUBMODULE POLICY', each Red Bear" >&2
echo "fork worktree must be checked out on its canonical 'submodule/<name>'" >&2
echo "branch. The following forks are not:" >&2
echo "" >&2
for w in "${wrong[@]}"; do
echo " - $w" >&2
done
echo "" >&2
echo "Fix with (from the parent repo):" >&2
echo " for f in base bootloader installer kernel libredox redoxfs relibc syscall userutils; do" >&2
echo " (cd \"local/sources/\$f\" && git branch -m HEAD submodule/\$f 2>/dev/null || true)" >&2
echo " done" >&2
echo " ./local/scripts/push-fork-branches.sh" >&2
echo "" >&2
echo "Override (emergency only): REDBEAR_ALLOW_WRONG_BRANCH=1 $0 $*" >&2
exit 1
fi
}
redbear_stash_one() {
local label="$1"
local dir="$2"
@@ -316,6 +358,12 @@ if [ "${REDBEAR_ALLOW_DIRTY:-0}" != "1" ] && [ -z "${REDBEAR_RELEASE:-}" ]; then
fi
fi
# Per AGENTS.md § "BRANCH AND SUBMODULE POLICY (ABSOLUTE)": each Red Bear
# fork worktree must be on the canonical submodule/<name> branch.
if [ "${REDBEAR_ALLOW_WRONG_BRANCH:-0}" != "1" ] && [ -z "${REDBEAR_RELEASE:-}" ]; then
redbear_check_fork_branches
fi
if [ -x "$PROJECT_ROOT/local/scripts/verify-overlay-integrity.sh" ] && [ -z "${REDBEAR_RELEASE:-}" ]; then
echo ">>> Verifying overlay integrity..."
if ! "$PROJECT_ROOT/local/scripts/verify-overlay-integrity.sh" --quiet; then