Skip to content

fix(gbrain-sync): append .gbrain-source to consumer repo's .gitignore after successful attach#1433

Open
rmotgi1227 wants to merge 1 commit into
garrytan:mainfrom
rmotgi1227:fix/gbrain-sync-consumer-gitignore
Open

fix(gbrain-sync): append .gbrain-source to consumer repo's .gitignore after successful attach#1433
rmotgi1227 wants to merge 1 commit into
garrytan:mainfrom
rmotgi1227:fix/gbrain-sync-consumer-gitignore

Conversation

@rmotgi1227
Copy link
Copy Markdown

@rmotgi1227 rmotgi1227 commented May 11, 2026

… after attach

Summary

Fixes #1384

The v1.29.0.0 changelog promised:

.gbrain-source added to .gitignore so per-worktree pin doesn't leak across branches.

However, the shipped code only added .gbrain-source to gstack's own .gitignore — not to the consumer repo's .gitignore. This PR fixes that gap.

Root Cause

In bin/gstack-gbrain-sync.ts, after gbrain sources attach <id> succeeds, the .gbrain-source pin file is written to the consumer repo's root. The v1.29.0.0 implementation correctly hashes by path to give each worktree a unique source ID, but it never appended .gbrain-source to the consumer repo's .gitignore.

Without this gitignore entry, the pin file shows up as an untracked file and can be accidentally committed (via git add -A, pre-commit hooks, etc.), causing it to propagate to other branches and worktrees — silently overriding their per-worktree pin on next git pull.

Fix

After a successful gbrain sources attach, append .gbrain-source to <root>/.gitignore if not already present. The operation is:

  • Idempotent — checks for existing entry before writing
    • Safe — wrapped in try/catch; a non-writable .gitignore logs a warning and continues (never aborts the sync)
    • Minimal — only appends the one line; creates the file if it doesn't exist yet
    • Correct newline handling — adds a newline separator if the existing file doesn't end with one

Before / After

# Before v1.29.0.0 fix + this PR:
cd ~/myrepo && /sync-gbrain
git status
# → Untracked files:
#     .gbrain-source
grep '.gbrain-source' .gitignore || echo "MISSING"
# → MISSING

# After this PR:
cd ~/myrepo && /sync-gbrain
grep '.gbrain-source' .gitignore
# → .gbrain-source      ← correctly added
git status
# → nothing to commit (pin file is ignored)

Why this matters for Conductor users

Conductor users run /sync-gbrain in multiple sibling worktrees of the same repo+branch. Each worktree correctly gets a different path-hash source ID (per v1.29.0.0), but if either pin gets committed, git pull in the sibling overwrites the local pin and routes gbrain queries to the wrong worktree's code source. This is exactly the failure mode the changelog claimed to prevent.

Single-worktree users aren't badly affected but still benefit from a clean git status.


View in Codesmith
Need help on this PR? Tag @codesmith with what you need.

  • Let Codesmith autofix CI failures and bot reviews

… after attach

Add .gbrain-source to consumer repo's .gitignore to prevent accidental commits.
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.

/sync-gbrain doesn't add .gbrain-source to consumer repo's .gitignore (v1.29.0.0 changelog promised it)

1 participant