feat(templates): scaffold a .gitignore that excludes .env and .venv - #513
Open
michaelxu2288 wants to merge 2 commits into
Open
feat(templates): scaffold a .gitignore that excludes .env and .venv#513michaelxu2288 wants to merge 2 commits into
michaelxu2288 wants to merge 2 commits into
Conversation
agentex init writes an .env.example and tells users to create .env with their API key, and the Dockerfile path is protected by .dockerignore, but no template ships a .gitignore. A user who git-inits the scaffolded folder commits .env (and .venv) on the first add. Add a .gitignore to every template (secrets, Python artifacts, tool caches; .env.example stays committable) and a test asserting each scaffold renders it. Claude-Session: https://claude.ai/code/session_01HCVKnA7LeJZ44nxZz1uzF3
… of overwriting it Re-running agentex init on an existing project replaced the user's .gitignore. Keep the existing file and append only the scaffold entries that are missing, with a test for the merge. Claude-Session: https://claude.ai/code/session_01HCVKnA7LeJZ44nxZz1uzF3
Comment on lines
+127
to
+129
| existing_lines = {line.strip() for line in existing.splitlines()} | ||
| missing = [line for line in rendered.splitlines() if line.strip() and not line.startswith("#") and line.strip() not in existing_lines] | ||
| if missing: |
There was a problem hiding this comment.
When an existing .gitignore already contains !.env.example but does not contain .env.*, this order-insensitive check skips the existing negation and appends .env.* after it. Git uses the last matching rule, so rerunning agentex init then ignores .env.example even though the scaffold promises that the example file remains committable. Preserve the template rules as an ordered block or otherwise account for their effective order when merging.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agentex/lib/cli/commands/init.py
Line: 127-129
Comment:
**Gitignore Rule Order Breaks**
When an existing `.gitignore` already contains `!.env.example` but does not contain `.env.*`, this order-insensitive check skips the existing negation and appends `.env.*` after it. Git uses the last matching rule, so rerunning `agentex init` then ignores `.env.example` even though the scaffold promises that the example file remains committable. Preserve the template rules as an ordered block or otherwise account for their effective order when merging.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
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.
What
agentex initwrites.env.exampleand tells users to create.envwith an API key..dockerignoreprotects the image build, but no template ships a.gitignore, sogit init && git add .in a scaffolded folder commits.env(and.venv). Adds a.gitignore.j2to all 19 templates (secrets, Python artifacts, tool caches;.env.examplestays committable), registers it inroot_templatesincommands/init.py, and adds a parametrized test asserting every scaffold renders it with.envand.venv/excluded.Test
tests/lib/cli/test_init_templates.py: 45 passed (26 existing + 19 new). ruff clean.https://claude.ai/code/session_01HCVKnA7LeJZ44nxZz1uzF3
The PR is not yet safe to merge because rerunning initialization can make
.env.exampleignored in existing projects with a common preexisting negation.Fix with agent prompt
Summary
.env.examplecommittable in newly generated projects..gitignore.Reviews (2) · Last reviewed commit: "fix(init): merge scaffold entries into a..."