Repository navigation
fix(git): append missing patterns to .gitignore on github init (#458) - #461
Merged
Merged
Conversation
initialize_git_in_container wrote `.gitignore` with `cat > .gitignore` (truncate-and-write) containing only shell/cache entries. Two consequences: 1. Any workspace-supplied `.gitignore` (e.g. the one `/trinity:onboard` writes) was clobbered before `git add .`, so even a correct workspace deny-list gave no protection. 2. The hardcoded list did not contain `.env` or `.mcp.json`. Agents that had credentials materialized via `inject_credentials` after deploy leaked both files on the "Initial commit from Trinity Agent" push. Force-pushing the branch hides it from `main` but leaves retrievable orphan commits for ~30 days — a forced credential rotation event on a private repo and catastrophic on a public one. The `/home/developer/workspace` legacy path skipped the `.gitignore` step entirely, so legacy agents leaked everything in the tree. Fix (src/backend/services/git_service.py): - New `_GITIGNORE_PATTERNS` tuple: the prior 8 shell/cache entries (.bash_logout, .bashrc, .profile, .bash_history, .cache/, .local/, .npm/, .ssh/) plus the three files the bug report named — `.env`, `.env.*`, `.mcp.json`. Deliberately narrow; broader deny-lists (*.pem, credentials.json, etc.) are not added here. - New `_build_gitignore_merge_command(git_dir)` helper: emits `touch .gitignore && (grep -qxF -- <p> .gitignore || echo <p> >> .gitignore)` per pattern, so pre-existing entries (user-supplied or from a prior run) are preserved. Idempotent — second run is a no-op. `shlex.quote` handles outer/inner quoting. - Call site hoisted out of the `if git_dir == "/home/developer":` guard so the legacy `/home/developer/workspace` path is protected too. Regression tests (tests/unit/test_github_init_gitignore.py): - `test_preserves_preexisting_gitignore`: a workspace `.gitignore` with user rules (node_modules/, build/, *.log) survives the merge and the three credential patterns are present afterward. - `test_fresh_agent_ignores_env_and_mcp_json`: with no pre-existing `.gitignore`, the merged file contains `.env`, `.env.*`, `.mcp.json`. Both tests execute the real bash command against a temp directory (via subprocess), so shell-quoting bugs surface here rather than in production. Closes #458 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Single-line Recent Updates row pointing at github-repo-initialization.md, which was updated in 543d45f. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 of 3 tasks
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.
Summary
initialize_git_in_containerusedcat > .gitignore <<EOF(truncate-and-write) with a shell/cache-only pattern list, so any workspace.gitignorewas clobbered and.env/.mcp.json(written byinject_credentials) leaked on the initial commit to GitHub.touch .gitignore+grep -qxF <p> .gitignore || echo <p> >> .gitignoreper pattern). Idempotent; preserves any pre-existing workspace rules..env,.env.*,.mcp.json— alongside the existing 8 shell/cache entries. Runs for both/home/developerand the legacy/home/developer/workspacepath (previously skipped).Replaces PR #460 (auto-closed when the prior branch was deleted). That PR took a broader deny-list + base64 scaffolding; this is the narrow scope the bug report asked for.
Changes
src/backend/services/git_service.py— new_GITIGNORE_PATTERNStuple +_build_gitignore_merge_command()helper, call site hoisted out of the/home/developer-only guard.tests/unit/test_github_init_gitignore.py— 2 tests that run the real bash command against a temp dir: (1) pre-existing.gitignorepreserved; (2) fresh agent gets.env/.env.*/.mcp.jsonignored.docs/memory/feature-flows/github-repo-initialization.md— code snippet, expected-state checklist, and bug-fix note updated.Test plan
pytest tests/unit/test_github_init_gitignore.py -v— both new tests pass.pytest tests/unit/test_github_init_push.py -v— pre-existing 4 tests still pass.inject_credentialswrites.envand.mcp.json→initialize_github_sync→ inspect the "Initial commit from Trinity Agent" on GitHub, verify.envand.mcp.jsonare NOT in the tree,.gitignorecontains both patterns./home/developer/.gitignorewithnode_modules/\nbuild/\n→initialize_github_sync→ verify those lines survived and the three credential patterns are appended.Closes #458
Generated with Claude Code