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§
- 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. - container_
scan_ ready - Whether this machine has a publish guard that can judge a container agent’s push: gh-agent’s own hooks
directory is in place and was written by a gh-agent new enough for it. Read from that directory, not from
whatever program is called
gh-agenton the path, and with no program run. - 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_ as_ parameters - Hand the
GIT_CONFIG_*settings ofenv(an overlay onprocess) to the agent asGIT_CONFIG_PARAMETERSinstead ofGIT_CONFIG_COUNT/_KEY_<n>/_VALUE_<n>. - 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. - git_
config_ has - Whether the
GIT_CONFIG_*entriesgetsees namekey(matched without case). - git_
config_ has_ value - Whether the
GIT_CONFIG_*entriesgetsees givekeyexactlyvaluesomewhere (the name matched without case). - git_
config_ prepend - The variables that put
key = valuebefore everyGIT_CONFIG_*entrygetsees, the others renumbered after it: for a setting git reads in order, where an empty value clears the list built before it. - 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. - hooks_
written_ by - The (major, minor) version a hook gh-agent wrote names in its header line
(
# gh-agent publish guard: written by gh-agent 0.13.0; do not edit ...). - is_
guard_ hooks_ dir - Whether
dirholds hooksgh-agentwrote. - scan_
ready_ in - Whether the hooks in
dirare gh-agent’s guard, written by a gh-agent that can judge a container’s push. - set_
git_ config_ list - Make
keyhave exactlyvalues, in order, in theGIT_CONFIG_*entries ofenv(an overlay onprocess): its other slots go, the others are renumbered, and the values are appended. For a setting that is a list in git (credential.helper,url.<base>.insteadOf), where order matters and an empty value clears what came before. - without_
git_ config_ key envwithout theGIT_CONFIG_*entries forkey(matched without case), the others renumbered.- 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.