Skip to content

Latest commit

 

History

History
149 lines (116 loc) · 8.06 KB

update_constitution.md

File metadata and controls

149 lines (116 loc) · 8.06 KB

update_constitution.sh

Revision: 1 Last modified: 2026-12-04T17:48:16Z

Overview

The risk-free, fast-forward-only update of the constitution submodule inside a consuming project.

Run it when: you want the constitution in a project brought up to date, and you want a guarantee that nothing can be rewritten. It refuses anything that is not a fast-forward. Never force, never reset, never rebase, never push.

Its design promise in one sentence: a gitlink the project records is only ever replaced by a DESCENDANT of it.

How this differs from update.sh — the most common confusion, stated plainly:

update_constitution.sh update.sh
Scope only the constitution submodule the checkout and every submodule, recursively
Integration method fast-forward only — a diverged HEAD is refused rebase, with local commits replayed on top
Default target newest remote helixconstitution-v* release tag, else origin/main the branch's upstream tip
Local commits must be absent (refused as "unpushed work") kept, rebased
Project effect stages the new gitlink (commits only with --commit) nothing beyond the repos it updates
Hook runs the project's post_update_hook.sh runs the constitution checkout's hook when its HEAD moved

If you have local constitution commits you want to keep, update_constitution.sh will refuse you (exit 3) — that is by design, and update.sh is the tool for that case.

Prerequisites

  • bash, git.
  • The script must live inside the constitution submodule it updates.
  • The submodule must have no local changes (else exit 3).
  • Network access to at least one remote for the fetch; --check and --dry-run are not offline — they still fetch.
  • ssh with BatchMode=yes -o ConnectTimeout=10 always. Put keys/ports in ~/.ssh/config, not GIT_SSH_COMMAND: inherited git variables are dropped from the environment, with only the config-file selection, author/committer identity, CA bundle and protocol limits carried through.
  • Optional: nothing. No env vars are read.

Usage examples

# From a consuming project (standard layout)
bash submodules/constitution/scripts/update_constitution.sh

# Legacy layout works identically
bash constitution/scripts/update_constitution.sh

# Am I behind? Prints UPDATE_AVAILABLE=yes|no; moves nothing
bash submodules/constitution/scripts/update_constitution.sh --check

# Print the plan, change nothing (still fetches)
bash submodules/constitution/scripts/update_constitution.sh --dry-run

# Pin to a specific ref
bash submodules/constitution/scripts/update_constitution.sh --ref helixconstitution-v9.4.0

# Update, skip the post-update hook, and commit the gitlink bump
bash submodules/constitution/scripts/update_constitution.sh --no-hook --commit

# Update and let the Jev decision-layer hook run (it is off by default)
bash submodules/constitution/scripts/update_constitution.sh --jev-hook

# A non-standard layout
bash submodules/constitution/scripts/update_constitution.sh --project-root /path/to/project

What you should see: the before/after sha, the changelog delta, and — depending on mode — UPDATE_AVAILABLE=yes|no (--check) or already up to date (exit 0). With --commit it also commits the gitlink; without it the new gitlink is staged and left for you.

Exit codes

Code Meaning
0 Updated, or already up to date (--check: printed UPDATE_AVAILABLE=yes|no)
1 The post-update hook or the checkout failed
2 Usage error
3 Blocked — dirty submodule, unpushed work, diverged history, network failure, not a submodule, or --project-root equal to the submodule itself

Edge cases

  • Dirty submodule → exit 3, before any fetch.
  • Every fetch fails (offline) → exit 3. There is no offline mode for this script.
  • Unpushed work. Refused (exit 3) when HEAD is not on any remote branch nor in a tag the REMOTE has. A tag that exists only locally does not count: remote tags are read with git ls-remote --tags.
  • Diverged history → refused (exit 3). Only target == HEAD (already up to date) or target behind HEAD is accepted; nothing is forced.
  • Pre-release tags such as -rc1 are never chosen by the default helixconstitution-v* selection. Version ordering is numeric, so v9 < v10 < v100.
  • A recorded gitlink that is NEWER than the checkout, names a commit not in the checkout, or has diverged from it → exit 3, nothing staged, on every path including --check and --dry-run. Run git submodule update -- <path> first. Only a recorded gitlink that is an ancestor of the checkout counts as an update that was cut off.
  • A STAGED gitlink differing from both the committed gitlink and the checkout (something somebody staged) is never overwritten — exit 3 on every path, unless the pending marker is honoured: it names the checkout and its staged-before field equals the gitlink staged now, so a change staged after a cut-off run of this script is never mistaken for it.
  • An interrupted run (killed, or git add failed because the project's .git/index.lock was held) is finished by the next run, never reported as "already up to date": the run compares the submodule HEAD with the recorded gitlink, stages it, and re-runs the post-update hook if the marker .git/helix-update-pending says the earlier hook never finished. --check then prints UPDATE_AVAILABLE=yes.
    • Limit: the hook is re-run only while that marker exists — not when --no-hook was used.
    • Limit: a submodule HEAD ahead of the target with an older recorded gitlink is only reported (NOTE), never staged.
  • --check / --dry-run are not offline. They still run git fetch --quiet --tags per remote, updating the submodule's remote-tracking refs and tags. They never move HEAD or a local branch, never touch the working tree, and never change the project.
  • --project-root equal to the submodule itself → exit 3.

Internal behaviour

  1. Find the submodule it lives in and the project that records it (both layouts).
  2. Refuse (exit 3) if the submodule has local changes.
  3. Fetch every remote, tags included. All fetches failing → exit 3. HEAD on no remote branch and no remote tag → exit 3 (unpushed work).
  4. Choose the target: --ref, else the newest release tag on a remote (helixconstitution-vN(.N)*, numeric order, pre-releases never), else origin/main.
  5. Accept only a fast-forward: equal or behind → "already up to date" (exit 0); diverged → refuse (exit 3).
  6. Check the target out detached, run scripts/post_update_hook.sh from the project root with CONSTITUTION_JEV_HOOK=off (unless --jev-hook; skipped with --no-hook), print the before/after sha and the changelog delta, and stage the new gitlink in the project. It commits only with --commit.

The pending marker (.git/helix-update-pending in the project) is written before the checkout and removed after the hook, which is what lets the next run tell a finished update from a cut-off one.

Related scripts

  • scripts/update.sh — the rebase-everything recursive updater (docs/scripts/update.md). Reads local commits instead of refusing them.
  • scripts/install_constitution.sh — install/update with the upstream table, agent wiring and backups.
  • scripts/setup.sh — hook wiring, bootstrap mode.
  • scripts/post_update_hook.sh — the hook this script invokes and whose absence on --no-hook it documents.
  • docs/guides/update_script.md.

Last verified

2026-12-04 — source read (689 lines), bash -n clean, flags and exit codes read from the script's header contract and argument handling:

$ bash -n scripts/update_constitution.sh && echo PARSE-OK
PARSE-OK

Not executed in this pass: it moves a submodule checkout. To verify safely, run bash scripts/update_constitution.sh --check inside a throwaway clone — it prints UPDATE_AVAILABLE=yes|no and moves nothing (but does fetch).