687b2650be
Adds --report action mode to verify-patch-content.py that implements
the AGENTS.md § 'Orphan-Patch Supersession Decision Tree' algorithmically.
For each orphan, the action recommender outputs one of:
- INTEGRATED: fork log has >5 commits matching topic keywords;
the work IS in the fork under a different commit
subject. Safe to archive as superseded.
- FILE-RESTRUCTURED: target file no longer exists in fork (file
rebased past patch's expectations). Safe to archive.
- NO-TARGET-FILE: patch lacks +++ b/ header (non-actionable).
Safe to archive.
- MISSING-UPSTREAM: work NOT in fork; needs reapply or fork rebase.
Algorithm (in suggest_action_for_orphan):
1. Check if patch has no target file (lacks +++ b/) → NO-TARGET-FILE
2. Check if target file no longer exists in fork → FILE-RESTRUCTURED
3. Run 'git log -i --grep <topic-keyword>' on the fork; if >5 commits
match → INTEGRATED
4. Otherwise → MISSING-UPSTREAM
Validated with synthetic test: created a local/patches/relibc/
_test-synthetic-orphan.patch with target=lib/test/strange.rs (which
doesn't exist in fork). The recommender correctly classified it as
FILE-RESTRUCTURED.
Wired into pre-push-checks.sh as check #3a (verify-patch-content-action).
Future new orphans are auto-classified; the operator only needs to
verify the suggested classification matches reality and then archive
to legacy-superseded-2026-07-12/.
105 lines
3.3 KiB
Bash
Executable File
105 lines
3.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# pre-push-checks.sh — Optional pre-push hook for Red Bear OS.
|
|
#
|
|
# Usage:
|
|
# cp local/scripts/pre-push-checks.sh .git/hooks/pre-push
|
|
# chmod +x .git/hooks/pre-push
|
|
#
|
|
# Or invoke manually:
|
|
# ./local/scripts/pre-push-checks.sh # fail on any drift
|
|
# ./local/scripts/pre-push-checks.sh --soft # warn only
|
|
#
|
|
# Runs the critical pre-flight checks: sync-versions, verify-fork-versions,
|
|
# verify-patch-content, verify-collision-detection, and a self-test of the
|
|
# collision-detection algorithm.
|
|
# 1. sync-versions.sh --check (Cat 0 + Cat 1 + Cat 2 versions)
|
|
# 2. verify-fork-versions.sh (Cat 2 fork supremacy)
|
|
# 3. verify-patch-content.sh (no orphan patches)
|
|
# 4. verify-collision-detection.py (no config-vs-package conflicts)
|
|
#
|
|
# The hook is opt-in. Operators who don't want it should NOT install it.
|
|
# This is documented in local/docs/HOOKS.md (Phase 4.5+).
|
|
#
|
|
# Per AGENTS.md "Daily-upstream-safe workflow", these checks are the
|
|
# minimum safety net against silent drift. Without the hook, drift can
|
|
# only be caught at next build, which is too late for patches that
|
|
# have been silently moved/deleted.
|
|
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
cd "$ROOT"
|
|
|
|
soft_mode=0
|
|
if [ "${1:-}" = "--soft" ]; then
|
|
soft_mode=1
|
|
fi
|
|
|
|
fails=0
|
|
|
|
run_check() {
|
|
local name="$1"
|
|
local cmd="$2"
|
|
local label="$3"
|
|
echo ">>> $name"
|
|
if eval "$cmd" >"/tmp/pre-push-${name}.out" 2>&1; then
|
|
echo " OK"
|
|
else
|
|
local rc=$?
|
|
echo " FAIL (exit $rc)"
|
|
head -10 "/tmp/pre-push-${name}.out" | sed 's/^/ /'
|
|
fails=$((fails + 1))
|
|
fi
|
|
}
|
|
|
|
echo "=== Red Bear OS — pre-push safety net ==="
|
|
echo " (4 critical pre-flight checks)"
|
|
echo ""
|
|
|
|
# 1. sync-versions
|
|
run_check "sync-versions" \
|
|
"bash local/scripts/sync-versions.sh --check" \
|
|
"Cat 0 + Cat 1 + Cat 2 versions match branch"
|
|
|
|
# 2. verify-fork-versions
|
|
run_check "verify-fork-versions" \
|
|
"bash local/scripts/verify-fork-versions.sh" \
|
|
"Cat 2 fork supremacy + content check"
|
|
|
|
# 3. verify-patch-content
|
|
run_check "verify-patch-content" \
|
|
"python3 local/scripts/verify-patch-content.py" \
|
|
"No orphan patches in local/patches/"
|
|
|
|
# 3a. verify-patch-content --report action (Phase 6.4: decision-tree
|
|
# auto-suggestions for any orphans the operator must triage)
|
|
run_check "verify-patch-content-action" \
|
|
"python3 local/scripts/verify-patch-content.py --report action" \
|
|
"Orphan-patch decision-tree (INTEGRATED/SUPERSEDED/etc.)"
|
|
|
|
# 4. verify-collision-detection
|
|
run_check "verify-collision-detection" \
|
|
"python3 local/scripts/verify-collision-detection.py" \
|
|
"No config [[files]] vs package install collisions"
|
|
|
|
# 4a. verify-collision-detection --selftest (Phase 5.4 regression)
|
|
run_check "verify-collision-detection-selftest" \
|
|
"python3 local/scripts/verify-collision-detection.py --selftest" \
|
|
"Collision detection algorithm regression tests"
|
|
|
|
echo ""
|
|
if [ $fails -gt 0 ]; then
|
|
echo "=== RESULT: $fails check(s) failed ==="
|
|
if [ $soft_mode -eq 0 ]; then
|
|
echo "Push BLOCKED. To override: $0 --soft (or: REDBEAR_SKIP_PRE_PUSH=1 git push ...)"
|
|
exit 1
|
|
else
|
|
echo "Push allowed (--soft mode). $fails drift(s) present."
|
|
exit 0
|
|
fi
|
|
else
|
|
echo "=== RESULT: all 4 checks pass ==="
|
|
echo "Push allowed."
|
|
exit 0
|
|
fi
|