diff --git a/local/scripts/build-redbear.sh b/local/scripts/build-redbear.sh index 0210904730..8f6b6e8dcd 100755 --- a/local/scripts/build-redbear.sh +++ b/local/scripts/build-redbear.sh @@ -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/" +# 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/'" >&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/ 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