You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Refuse a Blanket git add in Linked Worktrees, Not Only in a Primary Checkout #4462
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.
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:
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.
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".
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.
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.
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.
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.
Activity
ptr727 commentedon Nov 26, 2026
Triage question, 2026-11-26.
Do you approve extending the write guard's blanket
git addrefusal 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 wheregit rev-parse --git-dirand--git-common-diragree, which is a primary checkout. In a linked worktree, where every task is required to run, nothing refusesgit add -A,git add ., orgit commit -a. A downstream session rangit add -N .in its task worktree unrefused, and it staged nothing only because no untracked file was there. The change is underhost-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_allowsrefuses every option before the paths, so reusing it unchanged would also refusegit add -N <file>, which the issue wants allowed. Second, a host hook fires in every session on the machine, including a throwawaygit initrepository in a temporary directory, where a blanket add sweeps nothing anyone else owns.Options:
originremote (recommended). A new numbered requirement refusesgit addwith.,*, a glob, pathspec magic, a directory, or-A,--all,-u,--updatewith no pathspec. It also refusesgit commit -aand--all. It applies in any checkout whoseoriginresolves, primary or linked, and passes a repository with noorigin, which is the disposable workspace case. Options such as-N,-p, and-vare 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.-A,--all,.,*,-uand--updatewith no pathspec, andcommit -a, in a checkout with anorigin. 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".originscoping. 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.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.mdrequirement 6 and its in-place exemption.gh-write-guard.py_is_primary_checkout,_in_place_allows, and_COMMIT_SWEEPSonmain.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.ptr727 commentedon Nov 26, 2026
Maintainer's answer, 2026-11-26 triage: option 1, approved as a design. One shared explicit-path predicate refuses a blanket
git addin any checkout that has anorigin, linked worktrees included.-Nand-pwith named files stay allowed, and a disposable repository with nooriginpasses. The edit is underhost-setup/agent-safety/, so an attended run implements it and the merge waits on the maintainer reading the diff.ptr727 commentedon Nov 27, 2026
Maintainer's answers on the drive's review findings, 2026-11-26:
gh-write-guard.py, for example with data-driven option tables, and keeptests/test_guard_size.py's 2500-line ceiling unchanged. Split into a sibling module the installer copies only if compacting frees too little.UnboundLocalError;git stageas a synonym foradd(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-treeandGIT_DIRhonored through_named_git_dir; and a selftest of the realgit remote get-url originpath.git add -nandgit commit --dry-run.Refuse a Blanket Stage in Any Checkout With an Origin and Pin the Rul…