beads/.gitattributes
seanmartinsmith 3fa0e23032
fix(setup): prevent doubled BEGIN/END markers from CRLF embedded template (#3553)
When bd is built from a Windows checkout (default core.autocrlf=true),
//go:embed reads CRLF bytes from the working tree for
internal/templates/agents/defaults/beads-section.md. templateBody()'s
LF-only TrimPrefix/TrimSuffix then failed to strip the legacy markers
inside the embedded body, so RenderSection wrapped them with fresh
markers — producing two nested BEGIN/END pairs in any AGENTS.md
written by bd setup mux/claude/etc.

bd setup mux --remove only stripped the outer pair (find-first
semantics), leaving a stray <!-- END BEADS INTEGRATION --> in the
user's file. TestRemoveMuxProjectRemovesBothLayers caught this on
Windows.

Two complementary fixes:

1. Pin internal/templates/agents/defaults/*.md to eol=lf in
   .gitattributes. Embedded templates are shipped data, not
   user-edited text, and should never carry CRLF.
2. Normalize CRLF→LF in templateBody() before stripping markers.
   Defensive against future templates added without a gitattributes
   pin.

Adds TestRenderSectionFullSingleMarkers as a direct regression guard
(asserts exactly one BEGIN and one END in RenderSection output).

Fixes #3552
2026-04-27 13:41:45 -07:00

10 lines
505 B
Text

# Shell scripts must always use LF line endings (especially git hook templates)
*.sh text eol=lf
cmd/bd/templates/hooks/* text eol=lf
# Embedded markdown templates are shipped data, not user-edited text. Pin LF so
# Windows checkouts (default core.autocrlf=true) don't bake CRLF into //go:embed
# bytes, which breaks LF-only marker stripping in templateBody() and produces
# doubled BEGIN/END BEADS INTEGRATION markers in installed AGENTS.md (#3552).
internal/templates/agents/defaults/*.md text eol=lf