Repository navigation
fix(init): walk the template through one pruned candidate emitter - #1715
Merged
Merged
Conversation
This was referenced Sep 25, 2026
c-vigo
added a commit
that referenced
this pull request
Sep 25, 2026
…1722) ## Description #1715 made `COPY_PRUNE_NAMES=(.git .venv)` the single source of truth for the copy step's prunes, consumed by both rsync copies and by `emit_template_candidates` (the `u+w` sweep, the substitution pass, the `+x` sweep). The `--preview` classifier was left out because it needs the source-relative path for destinations that do not exist yet. It kept its own `! -path "*/.git/*" ! -path "*/.venv/*"`, which differs in kind: `-path` skips only a directory's *contents*, while the emitter, like rsync, prunes any entry *named* `.git` or `.venv`. So a file with one of those names, at any depth, was reported as ADDED but never copied. `dest → rel` is lossless — both sides glue with the same `"$WORKSPACE_DIR/"` — so the preview now consumes the emitter and strips the prefix. That deletes the duplicated walk and gains the `-L` / `-mindepth 1` / basename-prune semantics for free. The emitter moves up next to `COPY_PRUNE_NAMES` (a pure, verbatim move) because the preview block precedes its old definition point. `-type f` stays explicit (the emitter defaults to `-true`). The two `docs/issues|pull-requests` predicates stay, with their comment corrected: they came from #951 to mirror rsync excludes that #1466 later deleted, the template ships neither path, so they are report-only. The report is byte-identical on the pristine template: `--preview --force` before and after diffed clean (117 ADDED rows, same order) — the prune only removes entries and traversal order is unchanged. ## Type of Change - [ ] `feat` -- New feature - [x] `fix` -- Bug fix - [ ] `docs` -- Documentation only - [ ] `chore` -- Maintenance task (deps, config, etc.) - [ ] `refactor` -- Code restructuring (no behavior change) - [x] `test` -- Adding or updating tests - [ ] `ci` -- CI/CD pipeline changes - [ ] `build` -- Build system or dependency changes - [ ] `revert` -- Reverts a previous commit - [ ] `style` -- Code style (formatting, whitespace) ### Modifiers - [ ] Breaking change (`!`) -- This change breaks backward compatibility ## Changes Made `assets/init-workspace.sh` - `emit_template_candidates` moved verbatim to just below the `COPY_PRUNE_NAMES` / `COPY_PRUNE_EXCLUDES` block - Preview walk: `while IFS= read -r -d '' workspace_file; do rel_path="${workspace_file#"$WORKSPACE_DIR"/}"; …` fed by `emit_template_candidates "$TEMPLATE_DIR" -type f ! -path "*/docs/issues/*" ! -path "*/docs/pull-requests/*"`; everything downstream of `rel_path` / `workspace_file` unchanged; comment corrected (#951 / #1466) `tests/bats/init-workspace.bats` - RED next to the #951 `.venv` over-report test: a file `.git` and a nested file `pkg/.venv` in the template must not appear as ` + .git` / ` + pkg/.venv` in `--preview --force` (`refute_line`, never `--partial ".git"`) after a positive anchor on a known ADDED row, and neither exists after a real `--force` scaffold. On `dev` both phantom rows appear ## Changelog Entry No changelog needed — the issue says so; the visible change is two phantom preview rows for a template shape devkit does not ship. ## Testing - [x] Tests pass locally (`just test`) - [x] Manual testing performed (describe below) ### Manual Testing Details - `bats -j 4`: `init-workspace.bats` 305/306 (the one failure is pre-existing and environmental — test 296 needs PyYAML in the plain `nix develop` python; identical at the parent commit), `upgrade-atomicity.bats` 6/6, `install.bats` 95/95 - Pristine-template `--preview --force` report before vs after: identical - `shellcheck -x` and `bash -n` clean; file mode still 100755; `prek run --all-files` → 55 hooks passed ## Checklist - [x] My code follows the project's style guidelines - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation accordingly (edit `docs/templates/`, then run `just docs`) - [ ] I have updated `CHANGELOG.md` in the `[Unreleased]` section (and pasted the entry above) - [x] My changes generate no new warnings or errors - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] Any dependent changes have been merged and published ## Additional Notes Rewriting the script through a temp file and `mv` silently dropped its executable bit once during implementation; the structural BATS test caught it and the committed blob is 100755. Refs: #1716
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Two latent bugs in the template-tree walks of
assets/init-workspace.sh, one fix.#1700.
sweep_scaffold_writablewalkedfind -L "$src_dir" -mindepth 1with no excludes. The image bakes a.venvinside/root/assets/workspacethat the copy step'srsync --exclude='.git' --exclude='.venv'never ships, so the sweep walked hundreds of baked venv paths and, wherever a consumer's own.venvhad a file at the same relative path,chmod u+w'd a consumer file. Harmless in practice, but the same blind spot #1693 closed for placeholder substitution: a template-derived walk that does not apply the copy step's excludes reaches files devkit did not ship.#1703. Three walks derived a workspace path with
rel="${src_path#"$src_dir"/}". With a trailing slash onTEMPLATE_DIR, GNUfindprints/…/workspace/a.txt, the prefix/…/workspace//never strips, the destination never exists, and the walk silently does nothing — exit 0, no warning. Reproduced: withTEMPLATE_DIR=".../tmpl/"a read-only preservedREADME.mdstayed444(control:644), a shippedpkg/lib.shstayed644(control:755), and--preview --forceprinted "118 file(s) will be ADDED" as absolute-path garbage where the control printed "98 file(s) will be OVERWRITTEN".The design correction from triage. "Derive the excludes from
EXCLUDE_ARGS" does not work:.git/.venvare literal rsync flags and never inEXCLUDE_ARGS;EXCLUDE_ARGSis built after the--previewwalk and is unset in the smoke branch; and feeding the preserved-file/mode excludes into the chmod sweep would stop preserved consumer files gettingu+w. The single source of truth isCOPY_PRUNE_NAMES=(.git .venv), consumed by both rsync calls (via a derivedCOPY_PRUNE_EXCLUDES) and by one shared emitter:It normalises
${1%/}, prunesCOPY_PRUNE_NAMESby basename at any depth under-L, and is consumed bysweep_scaffold_writable(no type predicate — directories keep gettingu+w),emit_substitution_candidates(-type f, #1693's routine) and the+xsweep (-type f -name '*.sh'). The--previewclassifier walk stays separate (it needsrelfor absent destinations and carries extradocs/issues|pull-requestsexcludes); it and every other reader are fixed by one line after the only assignment:TEMPLATE_DIR="${TEMPLATE_DIR%/}".Type of Change
feat-- New featurefix-- Bug fixdocs-- Documentation onlychore-- Maintenance task (deps, config, etc.)refactor-- Code restructuring (no behavior change)test-- Adding or updating testsci-- CI/CD pipeline changesbuild-- Build system or dependency changesrevert-- Reverts a previous commitstyle-- Code style (formatting, whitespace)Modifiers
!) -- This change breaks backward compatibilityChanges Made
assets/init-workspace.shTEMPLATE_DIR="${TEMPLATE_DIR%/}"right after the default assignmentCOPY_PRUNE_NAMES=(.git .venv)+ derivedCOPY_PRUNE_EXCLUDES; both rsync copies (smoke and normal) use it instead of literal--excludeflags; the smoke--exclude='/CHANGELOG.md'is unchangedemit_template_candidates()added before its first consumer;sweep_scaffold_writable,emit_substitution_candidatesand the+xsweep now read destinations from it (NUL-delimited end to end); their own-e && ! -L/-f && ! -L/-ffilters and the batchedxargs chmodare untouchedCOPY_PRUNE_NAMEStests/bats/upgrade-atomicity.bats.venv/lib/pyvenv.cfgand nestedpkg/.venv/xwith0444workspace twins must stay0444(failed ondevwithexpected 444 / actual 644)tests/bats/init-workspace.bats*.shis+x, and--previewreports OVERWRITTEN/ADDED correctly (failed ondevat the first assertion)Changelog Entry
No changelog needed — both issues say so; the sweep's visible effect on consumer files was a no-op
u+won venv files, and no in-repo caller passes a trailing slash today.Testing
just test)Manual Testing Details
bats -j 4 tests/bats/init-workspace.bats tests/bats/upgrade-atomicity.bats→ 311 ok, 0 failures (twice);bats -j 4 install.bats release-mirror-fold.bats release-mirror-fold-lint.bats→ 111 okshellcheck -x assets/init-workspace.shclean;bash -ncleandevand gone on the branch (see Description)prek run --all-files→ all hooks passedChecklist
docs/templates/, then runjust docs)CHANGELOG.mdin the[Unreleased]section (and pasted the entry above)Additional Notes
The production case (baked
.venvof store symlinks in the image) is covered by analogy through tempTEMPLATE_DIRs, as the existing init-workspace tests are.unset 'prune[-1]'needs bash ≥ 4.3, which the dev shell and image both have.Refs: #1700, #1703