Skip to content

Refuse a Blanket git add in Linked Worktrees, Not Only in a Primary Checkout #4462

Done

Description

@ptr727

GOVERNANCE.md "Repository Boundaries and Write Safety" says staging is by explicit path, never git add -A or git add .. The gh-write-guard hook enforces that only for the in-place-commit exemption in a primary checkout, through _in_place_allows, which refuses ., *, a pathspec magic, a glob, or a directory. In a linked worktree, where every task is required to run, requirement 6 does not apply, and nothing refuses a blanket add.

Near-miss observed in a downstream session (ptr727/HomeAutomation-Config#2024): an agent ran git add -N . in its task worktree to make a diff-scoped linter see untracked files. It ran unrefused. It staged nothing only because the worktree happened to hold no untracked files.

Reproduce with a constructed worktree:

git init -q /tmp/demo && cd /tmp/demo && git commit -q --allow-empty -m base
git worktree add -q -b task /tmp/demo-task
cd /tmp/demo-task && touch stray.txt && git add -N .   # not refused by the guard
git status --short                                     # " A stray.txt"

Suggested shape: apply the existing path checks from _in_place_allows to every git add, and to git commit -a / --all, in any checkout, not just in the primary-checkout exemption. Each pathspec would be a named file, never ., *, a glob, a magic pathspec, or a directory, and -A, --all, -u and --update with no pathspec would be refused. git add -N <file> with an explicit file stays allowed.

Activity

  1. ptr727 commented on Nov 26, 2026

    @ptr727
    OwnerAuthor

    Triage question, 2026-11-26.

    Do you approve extending the write guard's blanket git add refusal from the primary-checkout exemption to linked worktrees? GOVERNANCE.md "Git and Commit Rules" says to stage by explicit path only, never with a blanket add. The guard enforces that only inside requirement 6's in-place exemption, through _in_place_allows. Requirement 6 fires only where git rev-parse --git-dir and --git-common-dir agree, which is a primary checkout. In a linked worktree, where every task is required to run, nothing refuses git add -A, git add ., or git commit -a. A downstream session ran git add -N . in its task worktree unrefused, and it staged nothing only because no untracked file was there. The change is under host-setup/agent-safety/, the agent's own guard, so a human approves it. An approval here lets an attended run implement it and drive the pull request. The merge still waits on your go-ahead after you read the diff.

    The primary-versus-linked test does not limit the new check, since it would apply in both. What does matter is two things. First, _in_place_allows refuses every option before the paths, so reusing it unchanged would also refuse git add -N <file>, which the issue wants allowed. Second, a host hook fires in every session on the machine, including a throwaway git init repository in a temporary directory, where a blanket add sweeps nothing anyone else owns.

    Options:

    1. Approve, scoped to a checkout with an origin remote (recommended). A new numbered requirement refuses git add with ., *, a glob, pathspec magic, a directory, or -A, --all, -u, --update with no pathspec. It also refuses git commit -a and --all. It applies in any checkout whose origin resolves, primary or linked, and passes a repository with no origin, which is the disposable workspace case. Options such as -N, -p, and -v are allowed with named files. One path predicate is shared with the in-place exemption, so "explicit path" has one meaning. It costs a retry with named files for a new directory or a shell glob the guard sees unexpanded. The harm it closes is a stray untracked file, a scratch file or one holding a secret, swept into a commit and pushed, which the data rule treats as one-way once it posts.
    2. Approve the narrow form only. Refuse -A, --all, ., *, -u and --update with no pathspec, and commit -a, in a checkout with an origin. Allow a directory and a glob. Fewer false positives, but a directory add still sweeps whatever that directory holds, and the guard then holds two meanings of "explicit path".
    3. Approve the issue's shape as written, in every checkout. The same checks as option 1 with no origin scoping. Strictest, but it refuses a blanket add in a disposable temporary repository too, where the rule's harm, another task's swept work, cannot arise.
    4. Decline and keep it prose. GOVERNANCE.md "Durable Knowledge and Self-Improvement" gates a host hook on a failure that recurs after the prose was read and on destructive harm. The record shows one near-miss in a task's own worktree, and the local strict review and pull request review see a swept file before merge. No change to the guard.

    Evidence: #4462 body and its reproduction. host-setup/agent-safety/README.md requirement 6 and its in-place exemption. gh-write-guard.py _is_primary_checkout, _in_place_allows, and _COMMIT_SWEEPS on main. GOVERNANCE.md "Git and Commit Rules", "Repository Boundaries and Write Safety", and "Durable Knowledge and Self-Improvement" on when a rule earns a host hook. No open pull request touches the guard.

  2. added
    decision
    on Nov 26, 2026
  3. ptr727 commented on Nov 26, 2026

    @ptr727
    OwnerAuthor

    Maintainer's answer, 2026-11-26 triage: option 1, approved as a design. One shared explicit-path predicate refuses a blanket git add in any checkout that has an origin, linked worktrees included. -N and -p with named files stay allowed, and a disposable repository with no origin passes. The edit is under host-setup/agent-safety/, so an attended run implements it and the merge waits on the maintainer reading the diff.

  4. removed
    decision
    on Nov 26, 2026
  5. ptr727 commented on Nov 27, 2026

    @ptr727
    OwnerAuthor

    Maintainer's answers on the drive's review findings, 2026-11-26:

    • Room under the ceiling: compact first. Make room inside gh-write-guard.py, for example with data-driven option tables, and keep tests/test_guard_size.py's 2500-line ceiling unchanged. Split into a sibling module the installer copies only if compacting frees too little.
    • Fix: the selftest UnboundLocalError; git stage as a synonym for add (and in requirement 6's always-deny set); separate-word option values counted as files (--pathspec-from-file, --chmod +x); commit pathspecs (-m x ., -i ., -o .) checked through the explicit-path predicate; --git-dir, --work-tree and GIT_DIR honored through _named_git_dir; and a selftest of the real git remote get-url origin path.
    • Allow: read-only git add -n and git commit --dry-run.
    • Decline: the mkdir-then-add race. It needs a compound command crafted to dodge the guard, which is not the accident this guard exists for.
  6. added a commit that references this issue on Nov 27, 2026
    ee90b1d
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