Help people move a .env out of a push instead of only refusing it #133
Problem#
Push protection refuses a push that adds a .env file (packages/git/src/protocol/policy.ts). That is right, but the refusal only says "keep secrets out of git", and the person must work out the fix themselves.
We'd like Source to handle a .env for people. It can't do that on the server: by the time a push arrives, git has sealed the file into the commit.
- Stripping it on the server changes the commit id. The local branch and the forge then disagree, every later push is a non-fast-forward, and the local history still holds the file.
- Keeping it publishes it. Any reader can fetch an object by its id, and the file goes to forks, to GitHub on synced repositories, and into every CI checkout, where no secret value may go.
- A
.envdoesn't say enough to become CI secrets. It names no environment, no hosts and no header. - A
src pushthat bypasses git has the same divergence problem. It also misses plaingit push, which is what agents and most people run.
Proposal#
Handle it on the developer's machine, before the commits leave it. Commits that were never pushed can be rewritten safely.
Refusal text. Make the push protection message give the exact steps:
push protection: .env looks like an environment file; keep secrets out of git. Undo the commit: git rm --cached .env && echo .env >> .gitignore && git commit --amend Share the file: src vault put .env Use it in CI: src secret set -f .env --env development --host <host>Small, and it helps people on plain git too.
src push. Wrapgit push:- Find the
.envfiles that the outgoing commits (@{u}..HEAD) add. - Offer to move them to the vault or to CI secrets, asking for the environment and the hosts.
- Remove the files from those local commits, keep them on disk, and add them to
.gitignore. - Run
git push.
The rewrite needs the developer's yes every time, by a prompt or a flag, never silently.
- Find the
Opt-in pre-push hook. The same check as a hook, installed per repository (from
src agent setupor a newsrc hooks install), so plaingit pushfrom people and agents gets it too. Never set the globalcore.hooksPath: it would override the developer's own hooks.
Open questions#
- Is step 1 enough on its own, or is the rewrite worth its risk?
- Should
src pushalso catch the known secret formats that push protection scans for (SECRET_PATTERNS), not just.envpaths? - Hook install: part of
src agent setup, or a separate command?
Sign in to join this conversation.