Expand description
Put gh-agent’s publish guard in front of every git push an agent makes.
gh-agent writes a git hooks directory whose pre-push scans what a push
to a public repository would publish and refuses it on a hit; the other
hooks in it run the repository’s own hook of that name. Git only uses it if
core.hooksPath points there, and a repository’s own core.hooksPath (this
repo sets .githooks) beats a global one. Configuration from the
environment (GIT_CONFIG_COUNT, GIT_CONFIG_KEY_<n>, GIT_CONFIG_VALUE_<n>)
beats both, so that is how agents get it.
The directory is computed the way gh-agent hooks-path computes it, from
the agent’s own env first and then this process’s, rather than by running
gh-agent on every spawn. It is only used once gh-agent has written it
(any gh-agent 0.5+ run as git’s credential helper does); an agent started
before that gets it at its next start. Without it the spawn goes ahead
unchanged: the guard is an extra check, never a reason to fail.
Like GH_CONFIG_DIR from backend::gh_guard, the entry is reserved: a value
for core.hooksPath already in the env is replaced, not kept.
Constants§
- COUNT 🔒
- HOOKS_
PATH_ 🔒KEY - MARKER 🔒
- The line
gh-agentwrites into every hook it generates. - MAX_
ENTRIES 🔒 - Larger counts already in the env are not trusted (and not looped over).
- META_
KEY_ PTYSHELL_ GIT_ HOOKS_ PATH - Block meta on an agent’s PtyShell: the hooks directory, which the PTY spawn
sets through
GIT_CONFIG_*(blockcontroller::shell::lifecycle). A PTY shell’s env is built from its own block, not from the agent’s, so the setting travels on that block, asgh_guard’s directory does.
Functions§
- apply_
publish_ guard apply_publish_guard_inwith the hooks directory this spawn’s env and this host give. Not called under test (seegh_guard::apply_gh_guard), so tests never read the host’s real hooks.- apply_
publish_ guard_ in - Point
core.hooksPathathooks_dirinenv, an overlay onprocess. - env_var 🔒
keyfromenv; on Windows, where variable names ignore case, in any casing.- gh_
agent_ hooks_ dir - Where
gh-agentwrites its hooks:GH_AGENT_HOOKS_DIR, else%LOCALAPPDATA%\gh-agent-hookson Windows and$XDG_DATA_HOME/gh-agent/hooks(default~/.local/share) elsewhere. - git_
config_ entries - The variables that set
key = valueon top of theGIT_CONFIG_*entriesgetalready sees. Every slot that nameskey(case-insensitively, as git does for the section and name) gets the value, since git uses the last one it finds; with none, a slot is appended. - hooks_
dir_ for - The hooks directory for a spawn whose own env is
env(falling back toprocessfor anything it doesn’t set), ifgh-agenthas written it. - is_
guard_ hooks_ dir - Whether
dirholds hooksgh-agentwrote. - parse_
count 🔒 - without_
hooks_ path envwithout itscore.hooksPathentries, the others renumbered: for a container, where the host’s hooks directory means nothing, but any otherGIT_CONFIG_*setting the agent’s env carries must still work.