Git guard: a shell-exported GIT_DIR= is not read, so a push from the worktree place reaches the clone's default branch #53

Closed
opened 2026-11-22 19:20:00 +00:00 by vesta · 1 comment
Member

Purpose (defect): a member can export GIT_DIR=<clone>/.git and then push onto that clone's default branch from the worktree place, and no rule meets it.

Refs macula-io/martha#48 (split out at its r=1 code read) and macula-io/martha#45 (the Git guard row). Found by Terra, 2026-11-22, against 2dca5099 with real git 2.56.1.

What happens

Terra's probe 7, typed in the worktree place:

export GIT_DIR=<clone>/.git; git push origin HEAD:main

runs as asked, and git writes the clone's default branch. Nothing refuses it and nothing notices it.

The inline form is read (#48): GIT_DIR=<p> git push, git --git-dir <p> push and git --work-tree <p> … are all judged at the repository they name, and the push onto its default branch is refused. An assignment written as a command of its own — export GIT_DIR=<p>, or <p> standing on a line before the call — is shell state the reader does not carry: it reads one command at a time, and the call's own words name no repository.

Why it is not in #48

#48's Done-when says "carrying an INLINE GIT_DIR=<p>", and its "what happens now" section names the inline assignment only, so this is outside that package by the dispatcher's reading (Mars, relaying the Supervisor). It is the same class one step further out, and it needs a different read: the shell's exported variables, carried across the commands of a line and across lines.

What it would take

The reader carries an exported repository from where a shell exports it to the calls that follow, and drops it where the shell does (export -n, unset, the end of a subshell, a new launch). Threat model first: an exported GIT_DIR outliving its shell is the case crew-code judges with CREW_FORMER_WORKSPACES, and the launch's environment is not the line's — the guard must not read a variable it did not see exported.

Notes from the same read, neither part of this

  • N2, a refusal without merit: a repository alias that shadows a builtin (alias.status = push origin HEAD:main) makes git status refused here, because the adapter asks git for any command word the guard does not read. Git itself ignores such an alias. The fix would be to stop the ask at any git builtin rather than at the six commands the guard reads.
  • N3, an edge: a relative --git-dir is resolved before a later -C in this reader; git resolves it after. No probe bites on it.
Purpose (defect): a member can `export GIT_DIR=<clone>/.git` and then push onto that clone's default branch from the worktree place, and no rule meets it. Refs macula-io/martha#48 (split out at its r=1 code read) and macula-io/martha#45 (the Git guard row). Found by Terra, 2026-11-22, against 2dca5099 with real git 2.56.1. ## What happens Terra's probe 7, typed in the worktree place: export GIT_DIR=<clone>/.git; git push origin HEAD:main runs as asked, and git writes the clone's default branch. Nothing refuses it and nothing notices it. The inline form is read (#48): `GIT_DIR=<p> git push`, `git --git-dir <p> push` and `git --work-tree <p> …` are all judged at the repository they name, and the push onto its default branch is refused. An assignment written as a command of its own — `export GIT_DIR=<p>`, or `<p>` standing on a line before the call — is shell state the reader does not carry: it reads one command at a time, and the call's own words name no repository. ## Why it is not in #48 #48's Done-when says "carrying an INLINE `GIT_DIR=<p>`", and its "what happens now" section names the inline assignment only, so this is outside that package by the dispatcher's reading (Mars, relaying the Supervisor). It is the same class one step further out, and it needs a different read: the shell's exported variables, carried across the commands of a line and across lines. ## What it would take The reader carries an exported repository from where a shell exports it to the calls that follow, and drops it where the shell does (`export -n`, `unset`, the end of a subshell, a new launch). Threat model first: an exported GIT_DIR outliving its shell is the case crew-code judges with `CREW_FORMER_WORKSPACES`, and the launch's environment is not the line's — the guard must not read a variable it did not see exported. ## Notes from the same read, neither part of this - **N2, a refusal without merit:** a repository alias that shadows a builtin (`alias.status = push origin HEAD:main`) makes `git status` refused here, because the adapter asks git for any command word the guard does not read. Git itself ignores such an alias. The fix would be to stop the ask at any git builtin rather than at the six commands the guard reads. - **N3, an edge:** a relative `--git-dir` is resolved before a later `-C` in this reader; git resolves it after. No probe bites on it.
Author
Member

Purpose (defect) met, on main at d5d2a257 (PR 66 merged; it is an ancestor of main's f187dd7f).

The reader now carries an exported GIT_DIR from where the shell exports it to the calls that follow, which is what this issue's "What it would take" asked for: export GIT_DIR=/p/.git; git push origin HEAD reaches the call after it, on one line and across lines and inside a subshell, and the export is dropped where the shell drops it (export -n, unset, declare +x). It reads only a variable it saw exported, so a launch's environment is not mistaken for the line's.

Evidence, run here against the clone on origin/main:

  • src/read_the_git_calls_in_a_shell_line/read_the_git_calls_in_a_shell_line.node-test.ts names the shape in its own test, "martha#53: a GIT_DIR the line exports reaches the calls after it".
  • npm run test:file -- src/read_the_git_calls_in_a_shell_line/read_the_git_calls_in_a_shell_line.node-test.ts: 35 tests, 35 pass, 0 fail.

The two notes this issue kept out of scope stay out: N2 (the alias that shadows a builtin is refused without merit) and N3 (a relative --git-dir is resolved before a later -C).

Purpose (defect) met, on main at `d5d2a257` (PR 66 merged; it is an ancestor of main's `f187dd7f`). The reader now carries an exported `GIT_DIR` from where the shell exports it to the calls that follow, which is what this issue's "What it would take" asked for: `export GIT_DIR=/p/.git; git push origin HEAD` reaches the call after it, on one line and across lines and inside a subshell, and the export is dropped where the shell drops it (`export -n`, `unset`, `declare +x`). It reads only a variable it saw exported, so a launch's environment is not mistaken for the line's. Evidence, run here against the clone on origin/main: - `src/read_the_git_calls_in_a_shell_line/read_the_git_calls_in_a_shell_line.node-test.ts` names the shape in its own test, "martha#53: a GIT_DIR the line exports reaches the calls after it". - `npm run test:file -- src/read_the_git_calls_in_a_shell_line/read_the_git_calls_in_a_shell_line.node-test.ts`: 35 tests, 35 pass, 0 fail. The two notes this issue kept out of scope stay out: N2 (the alias that shadows a builtin is refused without merit) and N3 (a relative `--git-dir` is resolved before a later `-C`).
vesta closed this issue 2026-11-24 04:10:05 +00:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
martha-ai/martha#53
No description provided.