Skip to content

Templates ship a .gitattributes, so a clone sees the bytes the pin describes (#51) - #58

Merged
brettheap merged 1 commit into
mainfrom
fix/templates-gitattributes
Sep 5, 2026
Merged

brettheap merged 1 commit into
mainfrom
fix/templates-gitattributes

Conversation

@brettheap

@brettheap brettheap commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Lane: xfactory-2 (xFactory-2)
Claim: #51 (comment)

Closes #51.

What this changes

Both root templates ship a .gitattributes with * text=auto eol=lf, pinned like every other copy. Brett Heap, 2026-09-05: "pick up #50 and #51 too".

A scaffolded project pins its copied files by sha256 in contracts/shape-pin.yaml, and validate-pins.py recomputes each digest from the bytes on disk. Git for Windows' installer default is core.autocrlf=true, so a colleague who did nothing but clone the finished project got CRLF in the worktree and every pinned row was false for them alone. #53 fixed the clone setup-project.py makes; this fixes the next person's, by putting the answer in the project where the digests are. No path is named in the file: every pinned file is text, and text=auto leaves binary detection with git for whatever the project adds later.

  • templates/assembly-root/.gitattributes and templates/family-root/.gitattributes, byte-identical, the WHY in the comment block.
  • scripts/shape_materialize.py: the file joins COPIED_VERBATIM and FAMILY_COPIED_VERBATIM. Nothing else in the materializer, in adopt-project.py, scripts/family.py or update-shape.py needed to change: they all read those tuples.
  • README: the worked example's tree, a paragraph under "Bootstrap is COPIED into the project", the Layout block; the template README's layout; hygiene cap 872 → 881 with the dated reason.

The proof, as tests

A git -c core.autocrlf=true clone --recurse-submodules of a scaffolded project — git honours that setting on every platform — shows w/lf for every pinned file in git ls-files --eol, and the clone's own validate-pins.py and validate-manifest.py exit 0. The control, the same clone with .gitattributes removed and committed first, shows w/crlf and FINDING shape-copy-drift on every copy: the bug report this closes. A family holder carries the same row. An existing project scaffolded before this change sees upstream-added: .gitattributes from update-shape.py check and takes it with apply --add .gitattributes, both validators green afterwards.

Expected downstream drift: every existing project and holder reports upstream-added: .gitattributes (exit 1) on its next update-shape.py check until a human runs apply --add. That is #29's machinery doing what it was built for.

Evidence

python3 -m pytest tests -q → 583 passed (573 on main, +10). Both CI jobs on this PR.

Merge word: Brett Heap, 2026-09-05, "merge #50 and #51 on green too".

🤖 Generated with Claude Code

Summary by Sourcery

Ship and pin a shared .gitattributes policy so cloned projects preserve the bytes recorded by their shape pins across platforms.

New Features:

  • Add .gitattributes to both root templates so scaffolded projects and family holders enforce LF worktree line endings for digest-pinned files.

Bug Fixes:

  • Prevent clone-time line-ending conversion from causing false pin-drift validation failures on systems using core.autocrlf=true.

Documentation:

  • Document the purpose and placement of the shared .gitattributes file in the project and template layouts.

Tests:

  • Add coverage for template and holder pinning, LF consistency, autocrlf-enabled clones, the failure control without .gitattributes, and updating existing projects with the new file.

…scribes (#51)

Git for Windows installs core.autocrlf=true by default; a colleague who did nothing but clone a scaffolded project got CRLF in the worktree and every pinned row went red for them alone. #53 covered the clone setup-project.py makes; this covers the next person. `* text=auto eol=lf` in both root templates, PINNED like every other copy (a file that says what the bytes are is worth nothing if it can be edited without the pin noticing); it joins COPIED_VERBATIM and FAMILY_COPIED_VERBATIM and nothing else in the materializer needed to change. Proof, as tests: a `git -c core.autocrlf=true clone` of a scaffolded project shows w/lf for every pinned file and its own validate-pins.py exits 0; the same clone with the file removed shows w/crlf and FINDING shape-copy-drift on every copy. Existing projects report `upstream-added: .gitattributes` on their next update-shape check and take it with `apply --add` (#29 machinery, tested). 583 tests.

Lane: xfactory-2 (xFactory-2)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 5, 2026 21:56
@brettheap

Copy link
Copy Markdown
Contributor Author

@codex review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 15 hours and 56 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@sourcery-ai

sourcery-ai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR makes .gitattributes a digest-pinned copied file in both root templates, enforcing LF worktree bytes for future clones regardless of core.autocrlf; documentation and comprehensive tests cover materialization, validation, the failure control, family holders, and expected upgrade drift for existing projects.

Sequence diagram for LF-preserving project clone validation

sequenceDiagram
    participant User
    participant Git
    participant Project
    participant Validator

    User->>Git: clone --recurse-submodules
    Git->>Project: Apply .gitattributes
    Project-->>Git: text=auto eol=lf
    Git->>Project: Checkout pinned copies with LF
    User->>Validator: validate-pins.py
    Validator->>Project: Read copied bytes
    Project-->>Validator: LF-normalized bytes
    Validator-->>User: Exit 0
Loading

File-Level Changes

Change Details Files
Add a pinned line-ending policy to both root templates and materialize it into projects and family holders.
  • Ship byte-identical .gitattributes files containing * text=auto eol=lf.
  • Register .gitattributes in both materializer copy lists so it is copied verbatim and included in shape-pin.yaml.
  • Document the rationale and resulting project layout in the main and template READMEs.
templates/assembly-root/.gitattributes
templates/family-root/.gitattributes
scripts/shape_materialize.py
README.md
templates/assembly-root/README.md
Extend regression coverage for cross-platform clone behavior and downstream update drift.
  • Verify both templates and scaffolded projects carry identical LF-only attributes files with matching SHA-256 pin rows.
  • Exercise a core.autocrlf=true clone and confirm pinned worktree bytes and validators remain green; retain a control proving the clone fails without the attributes file.
  • Verify existing projects and family holders report .gitattributes as upstream-added, and that apply --add installs it and restores validation.
tests/test_repo_hygiene.py
tests/test_scaffold_e2e.py
tests/test_family.py
tests/test_update_shape_add.py

Assessment against linked issues

Issue Objective Addressed Explanation
#51 Add a .gitattributes file with LF enforcement to both templates/assembly-root/ and templates/family-root/, so projects cloned with core.autocrlf=true retain the LF bytes described by their pins. ✅
#51 Ensure the new .gitattributes files are materialized into scaffolded projects and family holders, included in their shape-pin file lists, and validated as pinned copies. ✅
#51 Integrate the new template files with repository hygiene, documentation, tests, and update-shape drift handling, including reporting .gitattributes as upstream-added for existing projects until explicitly applied. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sonarqubecloud

sonarqubecloud Bot commented Sep 5, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The updated test fixture logic in tests/test_update_shape_add.py is not robust to CRLF line endings and can fail under core.autocrlf=true, which is a key scenario this PR targets.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR ensures digest-pinned “shape copy” files validate consistently across platforms by shipping a .gitattributes file in both root templates to force LF worktree checkouts regardless of core.autocrlf.

Changes:

  • Add byte-identical .gitattributes to templates/assembly-root/ and templates/family-root/, and include it in the materializer copy lists so it is copied + digest-pinned downstream.
  • Add end-to-end and hygiene tests covering autocrlf-enabled clones, “control” behavior without .gitattributes, and “upstream-added” adoption of the new file.
  • Update documentation to reflect the new copied/pinned .gitattributes and explain why it exists.
File summaries
File Description
tests/test_update_shape_add.py Extends “upstream-added” coverage to include the real .gitattributes addition and adoption path.
tests/test_scaffold_e2e.py Adds an end-to-end proof that core.autocrlf=true clones stay LF/green, plus a control that goes red without .gitattributes.
tests/test_repo_hygiene.py Adds hygiene assertions that both templates ship LF .gitattributes with the expected rule and matching bytes.
tests/test_family.py Updates holder copy/pin expectations and asserts the holder receives + pins .gitattributes.
templates/family-root/.gitattributes Introduces the holder’s LF enforcement policy for clones.
templates/assembly-root/.gitattributes Introduces the assembly root’s LF enforcement policy for clones.
templates/assembly-root/README.md Documents .gitattributes in the template’s shipped layout list.
scripts/shape_materialize.py Adds .gitattributes to both roots’ verbatim copy lists so it is copied and pinned.
README.md Documents .gitattributes in the scaffolded tree and explains its purpose relative to digest pins and autocrlf.
Review details
  • Files reviewed: 9/9 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +89 to +96
def unname_everywhere(text: str, entry: str) -> str:
"""`name_in_list` inverted, for every list at once.

How the copy lists read BEFORE a file joined them. The entry is matched as
a whole line so a comment mentioning the same name is left where it is: a
comment names nothing, and `upstream_copies` reads the tuples.
"""
return text.replace(f' "{entry}",\n', "")
@brettheap
brettheap merged commit 0a84d6c into main Sep 5, 2026
5 checks passed
@brettheap
brettheap deleted the fix/templates-gitattributes branch September 5, 2026 22:03
brettheap added a commit that referenced this pull request Sep 5, 2026
…counted 881 -> 945

#58 landed first and moved the README to 881 lines. This merge keeps its
`.gitattributes` rows and rationale entry, and re-counts this branch's cap
entry from 872 -> 936 to 881 -> 945 after it. The tree is identical to the
branch rebased onto 0a84d6c, on which 583 tests passed; the ruleset refuses a
force-push, so the rebase is carried as a merge.

Lane: xfactory-2 (xFactory-2)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
brettheap added a commit that referenced this pull request Sep 5, 2026
…ffold leaves (#54) (#57)

Brett Heap, 2026-09-05: "we have the case for windows only and wsl/linux
users and mac users. we need to make sure it is explained for all. i think we
have nothing so far for mac users" then "go, file the issue and pick it up
after #49 lands". Read against main after #46 and #49, macOS was one line
(`brew install gh`), nothing had ever run on a Mac, the `gh api` one-liner
decoded with a flag BSD base64 does not take, and a first-time user could
neither rehearse the run nor learn what a failure part-way leaves behind.

README § Quick start: the platform block is now Linux / macOS / Windows,
natively / Windows via WSL2. The macOS paragraph names where git, make and
python3 come from (the Xcode Command Line Tools), that Homebrew is its own
install (linked, not pasted) and prints the Apple Silicon PATH line, `brew
install gh`, `brew install git-filter-repo` only for adopting, and that the
stock /bin/bash 3.2 is enough because neither bash entry point uses newer
syntax. `base64 -d` becomes `base64 --decode`. A "Rehearse first, creating
nothing" paragraph documents `--local-remote-dir <dir>` and says exactly which
route still touches the network (the command fetches setup.sh and setup.sh
self-bootstraps; from a checkout nothing does) and that `--org` is only a
string there. An "If it fails part-way" paragraph gives the creation order
(spec, code, root last), that there is no rollback, the refusal of a second
run, `--reuse-empty-repo` as root-only, `gh repo delete` and its scope, and
`internal` as Enterprise Cloud only — each sentence checked against
scaffold-project.py, shape_materialize.py and setup.sh.

tests.yml gains a `tests-macos` job on macos-latest mirroring the Linux job
(same action shas, same pins, same per-invocation identity), plus a step that
prints /bin/bash --version and runs `/bin/bash -n` on setup.sh and on
openRepoShape separately, because `bash -n a b` parses only `a`. Green on
macos-latest is what "runs on a Mac" means here; there is no Mac on this side.

Adversarial Opus review before opening found four defects, all fixed: the
rehearsal paragraph claimed "no network" of a route that fetches setup.sh and
clones the standard; the failure paragraph attributed the "NOTHING has been
rolled back" line to any failure when only a failed push prints it, and
described a clone-failure message that setup.sh prints only when the target
already exists; the tests.yml comment claimed `bash -n` catches mapfile,
declare -A and local -n, which are runtime builtins, not grammar; and the
macOS prose asserted which bash the runner's /bin/bash is.

README 872 -> 933, cap moved with the rationale beside it. AGENTS.md
unchanged. 570 tests pass on Linux.

Copilot's one review finding on the PR is folded in: the macOS paragraph
now names the exit when the Command Line Tools' python3 is too old (older
Tools shipped 3.8). #58 landed first, so the cap entry reads 881 -> 945 after
#51's; the ruleset refuses a force-push, so the rebase rode as a merge commit.
583 tests pass on Linux; tests, tests-macos and tests-windows green on the
merged head; the macOS runner's /bin/bash is 3.2.57 and parsed both entry
points.

Lane: xfactory-2 (xFactory-2)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
brettheap added a commit that referenced this pull request Sep 6, 2026
…tes, the shim's --shape-ref length bound (#63) (#65)

* Empty $OPENREPOSHAPE_REPO means unset, the standard's own .gitattributes, the shim's --shape-ref length bound (#63)

Three Copilot inline comments read after their PRs merged (#56, #58, #60) and
deferred as cosmetic. None changes what a user sees today; each left a
statement in the tree that was not true, or a bound present in one entry point
and absent from the other.

setup-project.py: the comment above the $OPENREPOSHAPE_REPO read claimed that
checked_value refuses an empty value; the truthiness test in front of it means
an empty value is never checked and falls to DEFAULT_SHAPE_REPO, exactly as
setup.sh's ${OPENREPOSHAPE_REPO:-<default>} does. Ruled on #63: empty means
unset in both entry points. Behaviour unchanged; the comment now says so. One
test per entry point pins it offline by handing the child a
url.<file-uri>.insteadOf <default> rewrite through GIT_CONFIG_COUNT, so the
echoed clone line naming the default URL proves the empty value fell through.

.gitattributes at the root: the templates got theirs in #51; the checkout that
ships them had none, so a core.autocrlf=true clone of openRepoShape itself
turned every LF into CRLF and unname_everywhere() in the update-shape-add
tests, which matches a copy-list line whole, stripped nothing. Same rule,
* text=auto eol=lf, its own header; git add --renormalize is a no-op because
every tracked file is already LF. Hygiene tests pin the rule and its agreement
with both templates; the helper matches \r?\n anyway, for a checkout made
before this landed.

setup.sh: the --shape-ref case mirrored REF_RE's alphabet but not its 255
character bound, so an over-long ref reached git checkout in the temporary
clone. A length check after the case refuses it, naming the length rather than
echoing the value. bash 3.2 clean. A 256-character ref joins both parametrised
refusal tests; a dedicated shim test asserts the refusal names --shape-ref and
255, exits 2 and does not echo the value.

611 -> 619 tests.

Lane: xfactory-2 (xFactory-2)
Co-Authored-By: Claude Fable 5.1 <[email protected]>

* PR #65 review: the shim refuses an over-long or control-character --shape-ref before anything echoes it (#63)

Copilot on PR #65: the shape `case` echoed the raw --shape-ref in its refusal,
so a value holding a newline could forge a line onto stderr, and an over-long
ref that also failed the shape was echoed as 255+ characters of noise. Three
checks now run in order - length, then a control character, both refusing
without naming the value the way the OPENREPOSHAPE_REPO guard above them does,
then the shape case, which by then only ever sees a printable ref of at most
255 characters. Two tests: a newline-carrying ref is refused and the forged
line never reaches stderr; the over-long test is parametrised over a legal
shape and an illegal one, and neither is echoed.

Also from the review: the comment claiming the case is "only reached when
non-empty" (it runs unconditionally and matches nothing) is reworded, and the
hygiene test named "repositorys" is renamed.

Lane: xfactory-2 (xFactory-2)
Co-Authored-By: Claude Fable 5.1 <[email protected]>

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Templates ship a .gitattributes so a Windows clone of a scaffolded project passes its own gate (follow-up of #49)

2 participants