Repository navigation
Description
Description
Scaffold upgrades (just devc-upgrade, or curl … install.sh | bash -s -- --force .) mutate and delete files in the consumer repo — rsync over the working tree, mode-dependent pruning (rm -rf .devcontainer/ in direnv mode), placeholder substitution, sed -i on .vig-os. Today they run against any branch and any tree state: nothing stops an upgrade landing directly on main/dev or on top of uncommitted work, entangling a large mechanical diff with unrelated changes and making a bad upgrade hard to review or revert.
Add a preflight guard so an upgrade only proceeds on a dedicated working branch with a clean tree, plus a first-class diff preview. Fresh installs are exempt.
Field context: the 0.4.0 consumer validation (EXOMA/hyrr, EXOMA/talys — see #877, #878) showed exactly why isolation matters: upgrades silently clobbered .pre-commit-config.yaml and stranded recipes, and recovery relied on the upgrade being a distinguishable diff. A guard makes every upgrade a single revertible, reviewable commit series on its own branch by construction.
Problem Statement
install.sh --force(whichdevc-upgradewraps:.devcontainer/justfile.devc:77) performs no git checks at all before lettinginit-workspace.shrewrite the tree.init-workspace.shshows a conflict report (assets/init-workspace.sh:223-281) but with--no-prompts— the only modeinstall.shuses — it proceeds without confirmation.- An upgrade on a dirty tree mixes scaffold changes with WIP; an upgrade on
main/devviolates the org's issue → branch → PR flow and can't be PR-reviewed. install.sh --dry-runonly prints the container command (install.sh:490-499); there is no "what files would change" preview short of running the real thing.
Proposed Solution
Placement: host-side in install.sh, gating the --force (upgrade) path. Both supported entry points funnel through it (devc-upgrade → curl install.sh | bash -s -- --force .). The host is also the only place git state is reliably visible: the container mounts only $PROJECT_PATH, so in a git worktree (where .git is a file pointing at an unmounted gitdir) git is unusable inside the container — an in-container guard would misfire exactly in the worktree-heavy flows this org uses.
Guard logic (runs only when --force is given, i.e. upgrades; plain installs into empty dirs are untouched):
- Not a git repo / git unavailable → warn loudly ("no VCS safety net — cannot revert a bad upgrade") and require explicit confirmation (or
--skip-preflight) to continue. - Branch check — resolve
git -C "$PROJECT_PATH" rev-parse --abbrev-ref HEAD:- Refuse on
main,dev,release/*(prefix match), and detachedHEAD. - On a protected branch with a clean tree, offer to create and switch to
chore/devkit-upgrade-<version>and proceed there (chore branches carry no issue number per the branch-naming convention, so no issue is required). Non-interactively: refuse with that command as the hint. - Any other branch (e.g. an existing
feature/…) → allowed.
- Refuse on
- Clean-tree check — require empty
git status --porcelainoutput: no staged/unstaged changes and no untracked-unignored files. Gitignored clutter (.venv/,.direnv/, editor dirs) does not count as dirty, so real-world repos pass. Dirty tree → hard refusal (commit/stash first). - Escape hatch — a single
--skip-preflightflag bypasses both checks (it cannot be--force, which already means "upgrade"). Printed in every refusal message. - Exemptions:
--smoke-testruns skip the guard entirely — the downstream smoke-test CI checks outdevand runsinstall.sh --version <tag> --smoke-test --force --docker .headless (devcontainer-smoke-testrepository-dispatch.yml:205); without the exemption the guard would break the release gate.- Fresh installs (no
--force) are exempt; the existing "workspace not empty" refusal (assets/init-workspace.sh:142-147) already covers accidental re-runs. If a user re-runs the installer intending a fresh start over an existing scaffold, they are by definition on the--forcepath and get the guard.
Diff preview: add --preview that runs the existing conflict-report machinery (assets/init-workspace.sh:223-281 already computes OVERWRITTEN/PRESERVED sets) and exits before mutating anything, extended to also list mode-prune deletions (e.g. .devcontainer/ removal in direnv mode). install.sh forwards it. This is distinct from the existing install.sh --dry-run, which prints the container command only — document the difference in --help.
Tasks
-
install.sh: preflight function (repo detection, branch check withrelease/*prefix and detached-HEAD handling,git status --porcelainclean check), wired to the--forcepath only -
install.sh: interactive offer to create + switch tochore/devkit-upgrade-<version>; non-interactive refusal with hint -
install.sh:--skip-preflightflag;--smoke-testexemption; warn+confirm path for non-git directories -
init-workspace.sh:--previewmode — existing conflict report + prune-deletion listing, then exit 0 without touching the tree; forwarded frominstall.sh -
devc-upgraderecipe: surface the new flags in its help text (no logic change — it inherits the guard via install.sh) - Docs:
docs/MIGRATION.mdupgrade section +install.sh --helptext - Tests:
tests/bats/install.bats(guard: protected branches, dirty tree, detached HEAD, worktree fixture,--skip-preflight,--smoke-testexemption, non-git dir) andtests/bats/init-workspace.bats(--previewleaves tree untouched, lists deletions) - CHANGELOG
## Unreleased→ Added
Acceptance criteria
install.sh --forceonmain,dev,release/*, or detached HEAD refuses (exit ≠ 0) with an actionable message; on other branches with a clean tree it proceeds.- Dirty tree (tracked change or untracked-unignored file) refuses; gitignored files do not trip it.
- Guard works in a git worktree (
.gitfile) on the host. --skip-preflightbypasses;--smoke-testis unaffected end-to-end (smoke CI stays green).--previewproduces the add/overwrite/preserve/delete report and leaves the tree byte-identical.- Fresh install into an empty directory is unchanged.
- bats suites green.
Alternatives Considered
- Guard inside
init-workspace.sh(in-container): rejected as primary — git worktrees mount without their gitdir, so branch/status detection fails exactly where this org works most; also--smoke-testinternally setsFORCE=true(assets/init-workspace.sh:104-108), making exemption logic messier. A best-effort in-container warning could be added later for directpodman run … init-workspace.sh --forceinvocations, which bypass the host guard (accepted residual gap). - Denylist by exact names only (
main,dev,release): too brittle — release branches arerelease/X.Y.Z(prefix), and detached HEAD has no name at all. Refuse protected names/prefixes + detached HEAD, allow the rest. - Require an issue-numbered branch (
<type>/<issue>-…): over-strict; the branch-naming convention explicitly allowschore/<summary>without an issue for routine maintenance, which a scaffold upgrade is. - Split escape flags (
--allow-branch/--allow-dirty): more precise but two knobs for one rare action; a single--skip-preflightkeeps the mental model simple. - Hard refusal on non-git directories: a non-repo consumer is unusual but legitimate; refusing outright would strand them with no VCS to protect anyway. Warn + confirm instead.
Additional Context
- Relates: fix(workspace): scaffold upgrade strands base recipes — justfile.project is preserved but now owns sync/precommit/test, breaking the shipped ci.yml #877, fix(workspace): scaffold upgrade replaces .pre-commit-config.yaml, silently clobbering repo-specific hook config #878 (0.4.0 upgrade-path defects this guard would have contained), and feat(workspace): persist delivery mode, identity, and modules in .vig-os — declarative manifest with a new "bare" mode #885 (declarative
.vig-osmanifest), whose mode-switch case (devcontainer→direnv/baredeletes.devcontainer/) is the sharpest destructive path and should default to--previewfirst (owned there). - Entry-point map:
just devc-upgrade(assets/workspace/.devcontainer/justfile.devc:35-77) →curl install.sh | bash -s -- --force .→podman|docker run … /root/assets/init-workspace.sh --no-prompts --force(install.sh:467-488). - CI audit:
nix-image.yml:198runsinit-workspace.shdirectly against a freshmktemp -d(host guard not in path — unaffected); smoke-test dispatch uses--smoke-test --forceheadless on adevcheckout (exempted above). No other automatedinstall.shconsumers found; Renovate only bumps pins and never runs upgrades.
Impact
- Everyone running scaffold upgrades benefits: upgrades become isolated, reviewable, revertible diffs on their own branch, in line with the issue → branch → PR convention.
- Backward compatible for fresh installs and smoke-test automation. Behavior change only for
--forceupgrades on protected branches or dirty trees — which is the point;--skip-preflightrestores the old behavior. SemVer: minor.
Changelog Category
Added
Activity
feat(setup): preflight guard for scaffold upgrades and --preview diff…
feat(workspace): .vig-os declarative manifest with persisted mode/ide…
c-vigo commentedon Jul 8, 2026
Delivered by #903 (merged to
devon 2026-07-07). Closing as complete for milestone 0.5.chore: release 0.5.0 (#938)
test(init): give the install-script dry-run fixture a main branch
feat(init): preflight abort on non-main default branches (#1291)
test(bats): clone the both fixture for pure-setup upgrade sites
test(bats): isolate worktree.bats and tighten the BATS suite (#1709)