Revision: 1 Last modified: 2026-12-04T18:15:21Z
This is a library. It is sourced, never executed. Mode rw-rw-r--.
scripts/sync/sync_step_lib.sh is the one integration seam for upstream syncing. It defines a single
function, sync_step MODE PROJECT_ROOT ENGINE, and it exists so that other entry points do not each have to
invent their own way of invoking the sync engine:
scripts/setup.sh— first-time and repeat setup.scripts/post_update_hook.sh— STEP 5c, check only.
The point of the seam is that the caller chooses a mode, not a set of engine flags. That keeps the policy ("the post-update hook only looks; setup may integrate") in one reviewed place instead of scattered across callers, and it means an inherited environment variable can never add engine flags.
bash,git.$ENGINEmust be a real file —scripts/sync/sync_all_upstreams.sh.$PROJECT_ROOTmust be inside a git work tree (the function resolves its top level itself).- For
MODE=ask: a usable/dev/tty.
. scripts/sync/sync_step_lib.sh
# read-only, no network: the post-update default
sync_step offline "$PROJECT_ROOT" "$CONSTITUTION/scripts/sync/sync_all_upstreams.sh"
# fetch every remote, change nothing else
sync_step check "$PROJECT_ROOT" "$ENGINE"
# fetch and fast-forward; the flag is the consent, no prompt
sync_step apply "$PROJECT_ROOT" "$ENGINE"
# ask on /dev/tty before fetching and before every change
sync_step ask "$PROJECT_ROOT" "$ENGINE"
# do nothing, but tell the operator the exact command to run
sync_step off "$PROJECT_ROOT" "$ENGINE"
# inspect the outcome
echo "rc=$SYNC_STEP_RC verdict=$SYNC_STEP_VERDICT"MODE |
Engine arguments | Character |
|---|---|---|
off |
(none — runs nothing) | prints how to run it by hand, returns 0 |
offline |
--check --no-fetch --non-interactive |
read-only, no network; the post-update default |
check |
--check --non-interactive |
fetches every remote, changes nothing else |
apply |
--apply --non-interactive |
fetches and fast-forwards; the flag is the consent |
ask |
--apply --interactive |
the engine asks on /dev/tty before fetching and before every change; without a terminal the step is SKIPPED, never run unasked |
Every mode also passes --root <git top level> and --quiet.
sync_step returns (does not exit):
| Return | When |
|---|---|
0 |
everything except the FAILED verdict |
1 |
the engine exited 1 — an --apply integration step failed |
It always sets two variables for the caller:
SYNC_STEP_RC— the engine's exit code, or0foroff/ a skip.SYNC_STEP_VERDICT— one word from the closed set:OFF,SKIP,CURRENT,UPDATES-AVAILABLE,ATTENTION,FAILED,INCONCLUSIVE,LOCKED,BLIND,INTERRUPTED.
Engine exit → verdict mapping: 0→CURRENT, 3→UPDATES-AVAILABLE, 4→ATTENTION, 1→FAILED,
5→INCONCLUSIVE, 7→LOCKED, 6→BLIND, 8→INTERRUPTED. Exit 2 (usage) and any other code map to
BLIND — an uninterpretable answer is reported as blind, never as clean.
- Unknown mode — prints
SKIP, setsSYNC_STEP_VERDICT=SKIP, returns 0. An unrecognised mode never falls through to a default that would act. - Engine file missing —
SKIPwith a message naming the path, returns 0. PROJECT_ROOTnot a git work tree —SKIP, returns 0.MODE=askwithout a terminal —SKIPwith the advice to usecheckorapply. This is the important one: an interactive intent must never be silently downgraded into an unattended--apply.SYNC_STEP_EXTRA_ARGSin the environment — only the exact pair--out /absolute/diris honoured; anything else is ignored with a printed note. An inherited variable therefore cannot inject engine flags. (This is a test seam, added after a review finding.)offnever runs the engine at all, so it is safe in any environment.
- Defaults:
SYNC_STEP_RC=0,SYNC_STEP_VERDICT=OFF. - Switches on
MODEto build the engine argument array (offreturns immediately with the manual command). - Validates the engine file, then resolves
PROJECT_ROOTto its git top level. - For
ask, probes/dev/ttyand skips when it is not readable. - Applies the
SYNC_STEP_EXTRA_ARGSfilter described above. - Runs
bash "$ENGINE" <args> --root "$top" --quiet "${extra[@]}", capturing the status intoSYNC_STEP_RC. - Maps the status to
SYNC_STEP_VERDICTand prints one human line; returns 1 only forFAILED.
scripts/sync/sync_all_upstreams.sh/sync_all_upstreams.py— the engine this drives.scripts/setup.sh— a caller (may integrate).scripts/post_update_hook.sh— a caller (STEP 5c, check only).scripts/sync/verify_upstream_parity.sh— the read-only parity proof, a different question entirely.docs/scripts/sync_all_upstreams.md— the engine's own guide, including its exit-code table.
2026-12-04 — bash -n scripts/sync/sync_step_lib.sh → exit 0 (it is a library, so it is sourced, not run).
Behaviour check a reader can repeat in this checkout:
bash -c '. scripts/sync/sync_step_lib.sh; sync_step off . scripts/sync/sync_all_upstreams.sh; \
echo "rc=$? verdict=$SYNC_STEP_VERDICT"'Expected: a [sync-upstreams] off; to fetch every remote … line, then rc=0 verdict=OFF — nothing is fetched.