Revision: 1 Last modified: 2026-12-04T17:48:16Z
The rebase-based, recursive update of a constitution checkout and every submodule below it, at every depth.
Run it when: you want each repository in the tree brought onto its upstream branch while keeping your local commits on top. It is the "make my whole tree current without losing my work" tool.
What it explicitly is not: it never pushes, never forces, never deletes a branch, and takes no network action
other than git fetch (plus git submodule update --init for a submodule that is not yet checked out). It never
undoes history — nothing is written to a branch before the result is verified in a throwaway worktree.
The design point that makes it safe: the rebase runs in a temporary detached linked worktree; your branch, index, work tree and stash are untouched while it runs. Only after the result verifies does a single, uninterruptible publish step move the branch (compare-and-swap) and switch the tree, re-applying your uncommitted changes from a stash entry that is dropped only once it applied.
Do not confuse with update_constitution.sh — see "Related scripts".
bash,git≥ 2.38 for the merge-commit verification path (git merge-tree --write-tree). On older git, a repository whose local range holds merge commits is SKIPPED rather than risked.flockfor the run lock (falls back to amkdirlock, which offers no protection against akill -9ed run).timeout/gtimeoutoptional; without them a built-in watchdog is used, which cannot reap helper processes git started.- A clean-enough repository: no rebase/merge/cherry-pick/revert in progress, no unmerged files, no held
index.lock. - Env vars (NAMES only):
UPDATE_STATE_DIR(default${XDG_STATE_HOME:-~/.local/state}/constitution-update)UPDATE_BRANCH(defaultmain)UPDATE_TIMEOUT(default60)UPDATE_OWN_ORGS(defaultvasic-digital helixdevelopment helix helixconstitution)NO_COLOR— same as--no-color.
# Update the checkout this script lives in, and every submodule recursively
bash scripts/update.sh
# A specific repository
bash scripts/update.sh --root /path/to/checkout
# From a consuming project, targeting the embedded constitution
bash submodules/constitution/scripts/update.sh --root submodules/constitution
# See exactly what WOULD happen: no fetch, no lock, no snapshot, no change anywhere
bash scripts/update.sh --dry-run
# Offline: use the remote-tracking refs already present
bash scripts/update.sh --no-fetch
# Narrow the blast radius
bash scripts/update.sh --only submodules/helix_deps --max-depth 2
# Print the commands that would restore every repo of a saved snapshot (runs nothing)
bash scripts/update.sh --restore ~/.local/state/constitution-update/<snapshot>.jsonlWhat you should see: one progress line per repository, then a final table with counts for UPDATED / UP-TO-DATE / REBASED / CONFLICT / SKIPPED / FAILED / INTERRUPTED, the parent gitlinks that moved, and the elapsed time.
--dry-run prints WOULD-REBASE / WOULD-UPDATE — and prints them only when the verification in the throwaway
worktree passed.
| Code | Meaning |
|---|---|
0 |
Every repository updated or already current. A SKIPPED does not fail the run. |
1 |
At least one FAILED (e.g. every remote unreachable, rebase could not start, a git read that decides a step failed, an unreadable .gitmodules, an unsearchable submodule directory) and no conflict |
2 |
Usage error |
3 |
At least one CONFLICT (rebase conflict, or re-applying your uncommitted changes conflicted) |
4 |
Another update run holds the lock |
130 |
Interrupted (INT/TERM/HUP) |
The exit code answers "did the run complete", not "is everything current". A caller that must know whether a
specific repository is current reads its progress line or the skipped= count — never the exit code. This
asymmetry is deliberate: exit 1 is reserved for FAILED, a step this script could not decide or complete.
SKIPPED covers: an operation in progress, unmerged files, a held index.lock, a detached HEAD that would need a
rebase, a third-party pin left where it is, a submodule left uninitialised, and an uncommitted edit to a file marked
assume-unchanged.
assume-unchangededits. A local edit to a file markedassume-unchangedis invisible togit status/diff/stash, so no stash entry could hold it. It is detected by comparing the file with the index; the repository isSKIPPED, state unchanged, exit0.- A git read that cannot answer is
FAILED, never "no". An unreadable.gitmodulesor an unsearchable submodule directory is never taken as "no submodules" / "not checked out" (seetests/update/READS.md). - Third-party submodules are only moved to the commit the parent records (the pinned ref), never to upstream.
--init-third-partyoverrides the initialisation refusal. - Nested submodules are initialised only where
helix-deps.yamlallows (recursive_init: false/third_party: trueare honoured, §11.4.28(C)), and never inside a third-party submodule. - A detached HEAD follows upstream
main(ormaster). Only commits on no remote ref count as local, and a HEAD sitting on another remote branch is only fast-forwarded —SKIPPEDwhen it would need a rebase, because no copies of pushed commits are made. - Own-org classification. A bare
--own-orgname must equal an ORG (namespace) segment of the declared URL — never the repository name.org/repomatches a run of whole segments. A submodule markedthird_party: trueinhelix-deps.yamlis never own-org, whatever the flag says. - Merge commits in your local range. When the local range holds merge commits, the rebased tree is compared with
a plain merge (
git merge-tree --write-tree). A rebase that would drop manual changes made inside a local merge commit is never published. - A commit another git command makes during the publish step is reported as
CONFLICTwith the work tree left as it is — it would otherwise record your pre-update files on top of the update. kill -9is not covered. What it leaves behind depends on where it lands: only the script dying leaves the publish step to complete (and a second run refused with exit4until it does); the publish child dying before the branch moved changes nothing; dying after the move but before your changes were cleared leavesHEADat the result with the OLD files staged; dying after the clear leaves your changes only ingit stash list(stash@{0}, messageupdate.sh: autostash before updating to ...) — rungit stash pop.- After a clean run there is nothing to push unless you had local work. A parent whose submodule pointer moved shows the gitlink modified: commit it only when the pointer is a pushed commit that is not older than the one recorded — the report says when it is not.
Per repository, root first then every submodule recursively:
- Refuse to touch a repository with an operation in progress (rebase/merge/cherry-pick/revert), unmerged files,
a held
index.lock, or anassume-unchangededit in a file it needs to update. - Fetch every remote — the branch's configured remote first, then
origin, then the rest — each under a timeout. The freshest remote that has the branch wins (a descendant of the others); a diverging one is reported. - Snapshot
HEADinto a safety snapshot (JSON Lines, mode0600) after the fetch, before the first change.--restore FILEprints — never runs — the commands that would put every repository back. - Own-org repositories are brought onto the upstream branch by verify-before-rewrite:
a.
git rebase --rebase-merges <remote>/<branch>in a temporary detached linked worktree (rebase.updateRefsoff, merge backend); b. verify there: no conflict, no stop (a refusing hook, a failed signature), merge-commit tree equality when applicable, your uncommitted changes re-applied cleanly, no untracked file the update would overwrite; c. one publish step in its own process group: stash your changes (after re-checking they still equal what was verified), move the branch withgit update-ref HEAD <result> <old>before touching the work tree, checkHEADstill is<result>, re-check your changes,git read-tree -m -u <old> <result>, re-apply from the stash, drop it only after it applied, checkHEADagain. A failed switch moves the branch back with another compare-and-swap and restores your changes. - Report
CONFLICTwith the exact files and the command to resolve, and continue with the other repositories. - Print the progress line and the final table.
- Run
scripts/post_update_hook.shof the constitution checkout when itsHEADchanged — a failing hook never fails the update.
Any failure in 4a or 4b leaves the repository exactly as it was (CONFLICT or FAILED, "nothing changed").
--root DIR, --dry-run, --no-fetch, --only PATH, --timeout SEC, --own-org PATTERN (repeatable),
--no-init, --init-third-party, --max-depth N (default 8), --no-hook, --no-color, --quiet, --verbose,
--restore FILE, --help.
scripts/update_constitution.sh— the other updater, and the one most often confused with this. It updates only the constitution submodule, accepts only a fast-forward, never rebases, targets the newesthelixconstitution-v*release tag by default, stages the new gitlink in the project, and runs the project's post-update hook. It is the low-risk path.update.shis the rebase-everything path.scripts/post_update_hook.sh— invoked at the end when the constitution'sHEADmoved.scripts/lib/constitution_layout.sh— definesCL_GIT_SCRUB_VARS, the git variables this script unsets first.scripts/install.sh/scripts/setup.sh— install paths, not update paths.docs/guides/update_script.md— the full operator guide.
2026-12-04 — source read (1848 lines), bash -n clean, flag set and exit codes read from the script's own
argument parser and documented contract:
$ bash -n scripts/update.sh && echo PARSE-OK
PARSE-OK
$ grep -n 'UPDATE_STATE_DIR\|UPDATE_BRANCH\|UPDATE_TIMEOUT\|UPDATE_OWN_ORGS' scripts/update.sh | head -4Not executed in this pass: it rewrites branches in a real tree. To try it safely, use a throwaway clone and
--dry-run first, which performs the same verification with no fetch, no lock, no snapshot and no change.