Skip to content

Identity hook: spellings left after the .git-write story #160

Closed

Description

@don-petry

Part of the epic "Epic: slice 0, foundations. The repo holds the line, its context is tested, and the platform facts are recorded".

Follows "Identity hook: a write into git's directory, an alias that runs git, and xargs git are refused" (#156, closing #148). It had its one fix round for spellings. These came from Codex's review after it. None is a mistake a session would make by accident; the Stop check and the rulesets are the boundary (#23's ruling). Read them generally, not one at a time.

  • A for loop's word list longer than the 256-value cap is cut short. A .git path after the cap is never read: refuse when the expansion exceeds the budget.
  • popd doesn't restore the tracked directory, so cd .git; pushd /tmp; popd; cp /tmp/x hooks/pre-push; git push resolves the write under /tmp: track the stack, or fail closed after popd.
  • unzip with no -d writes under the current directory, and no path is reported: treat the tracked directory as the output root.
  • A substitution inside a case pattern is read before every ordinary command, not at its place, so a write after cd .git is resolved outside it.
  • tar's old-style option bundle (tar cf .git/a.tar src) isn't decoded.

Each with a test and a mutant.

Activity

  1. don-petry commented on Oct 18, 2026

    @don-petry
    ContributorAuthor

    Working rulings (overturnable in review)

    Solution Architect, delegated. On main at 72f8643 (#162). Builds on #156 (branch hooks/spellings-left, record 0030), which must merge first.

    One general rule. In four of the five, a write is resolved in the wrong place or at the wrong moment. The fifth is a reading cut short. So: a write is resolved where and when the shell makes it, and a reading the hook cuts short is one it cannot read. No new kind of word is read. Each part still reads only a path a PATH_WRITERS program is given, in a command that commits or pushes. Prose, patterns and loop lists stay data. Why false refusals stay rare: a part refuses only a path that resolves into .git, and no ordinary command writes there beside a commit.

    1. A loop past LOOP_MOST: close. When _bound would give more paths than the cap, refuse with git_directory_written, saying the loop is too long to read. Don't cut it short. This is the existing rule for what the hook cannot read within its budget. Its one false refusal: a commit command whose loop over more than 256 words writes a path holding the variable. Must-pass: a 300-word loop that writes no such path.

    2. popd: close, with no stack. Where the hook loses the directory, at popd, pushd with no directory or +N/-N, and cd -, it doesn't guess. A relative write is resolved against every directory the command has stood in, and refused if any puts it in .git. Why: a popped directory is always one the command stood in, and a full stack is more code for the same answer. This also closes cd -, which today reads the path as written.

    3. unzip with no -d: close, as a column of PATH_WRITERS. A writer whose words name no output writes where it stands. That covers unzip with no -d, tar extracting with no -C, curl -O/-J with no --output-dir, wget with no -O/-P, and patch with no file. For these, the directory as resolved in 2 is a place written. Must-pass: cd sub && unzip x.zip && git commit. Left to the boundary: an archive's own entry names.

    4. A substitution in a case pattern: close. shell.commands lists those substitutions before every command. List them where the pattern stands. The pattern stays data. Only the order changes, and protected.py gains the same. #156's case cases must still pass.

    5. tar's old-style bundle: close. When tar's first word has no dash and is all letters, read it as if dashed: cf is -cf. _options already decodes bundles. tar cf out.tar .git passes, since .git is a source. tar xfC h.tar .git is refused.

    Tests and mutants. Each part gets one test and one mutant. Each test also feeds a commit message and a PR body that spell its case out, and they pass. The must-pass cases cover braces and case, where false refusals came before.

    Decision 0032 adds to 0030, whose Decision stays. One row for the rule and its parts. One for what is left to the boundary: an archive's entry names, a directory the hook cannot expand, and unlisted writers such as python3 -c.

    One fix round. This story gets one fix round for spellings the bots find. After it, a new spelling is answered on the pull request and filed. A false refusal is always fixed in the story that finds it.

    Taken as a working ruling (the Maintainer may overturn it in review): all five spellings are closed, at about 60 lines. The only new false refusal is a commit command whose loop runs over more than 256 words and writes a path holding the loop variable, which a session is unlikely to write.

  2. don-petry commented on Oct 18, 2026

    @don-petry
    ContributorAuthor

    Two more, from CodeRabbit on #156 after its fix round (to be read generally with the rest):

    • An alias whose value is a feeder (xargs, parallel), a shell, source or eval hides git: alias x=xargs; echo push | x git and an alias for sh fed git push on stdin both pass. Treat such an alias as its value for the feeder and shell checks, as an alias for git already is.
    • A bracket expression into .git is read with - escaped, so .gi[s-u] or .gi[a-z] is not seen to match .git; a POSIX class (.gi[[:alpha:]]) closes the class early. Keep a range unescaped, and read a class the hook cannot parse as matching (fail closed).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions