fix(init): merge .gitignore with user content instead of overwriting (#6)#7
Merged
fix(init): merge .gitignore with user content instead of overwriting (#6)#7
Conversation
) Closes #6. Brownfield projects (Vite, Next, Astro, etc.) all ship a `.gitignore`. Before this change, `specflow init --here` reported it as a conflict and `--force` then backed up the user file and wrote specflow's stub — silently losing all the framework's ignores. This fix introduces a new `mergeable-project-root` bundle category and an append-block strategy in the FsWriter: - Specflow's `.gitignore` content is wrapped in fence markers `# --- Specflow: gitignore ---` / `# --- End Specflow: gitignore ---` - On a brownfield init, the block is appended to the existing user file. No backup, no conflict, no `--force` needed. - Re-running init replaces the existing block in place (idempotent). - `specflow upgrade` also extracts and re-syncs only the block; user lines outside the block are preserved. Lock SHA for mergeable files stores the canonical block body (no leading/trailing newlines), comparable against the body extracted from disk on subsequent reads. All 8 harnesses route `mergeable-project-root` to the same destination as `project-root` and stamp `mergeBlock: "gitignore"` on the bundle entry — no harness-specific divergence. Reproduction case (verified end-to-end on a fresh `npm create vite@latest`): user's 24-line Vite `.gitignore` is preserved verbatim with the specflow block appended at the end. Tests: 3 new integration tests cover greenfield, brownfield, and idempotency (316 pass total, 0 fail). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Closes #6.
Summary
Brownfield projects (Vite, Next, Astro, etc.) all ship a
.gitignore. Before this change,specflow init --herereported it as a conflict and--forcethen backed up the user file and wrote specflow's stub — silently losing all framework ignores.The fix introduces a new
mergeable-project-rootbundle category and an append-block strategy: specflow's.gitignoreis wrapped in fence markers and merged into any existing user file, non-destructively, idempotently, and without--force.Before / After
User file fully preserved. No
.gitignore.specflow.bak. No--forcerequired.Architectural shape
CoreCategoryvaluemergeable-project-root(currently only.gitignoreuses it).TemplateFile.mergeBlock?: stringfield carrying the fence label.DenoFsWriter.detectConflictsskips entries withmergeBlockset.DenoFsWriter.writeBundlereads any pre-existing file and merges viamergeIntoFile()from the newsrc/domain/merge_block.tshelper.mergeable-project-rootto the same destination asproject-rootand stampmergeBlock: \"gitignore\". No harness-specific divergence.Test plan
deno task test— 316 / 316 pass (was 313 before; +3 new brownfield tests).tests/integration/init_brownfield_gitignore_test.ts:.gitignore→ init succeeds without--force, both user lines and specflow block present, no.bakfile created.--forcedoes not duplicate the specflow block..gitignorewrapped in fence markers (same shape regardless of whether merge was needed).npm create vite@latestproject — Vite's 24-line.gitignore(logs, node_modules, dist, .DS_Store, .vscode, etc.) preserved verbatim with the specflow block appended.🤖 Generated with Claude Code