Skip to main content

Module publish_guard

Module publish_guard 

Source
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, as gh_guard’s directory does.

Functions§

apply_publish_guard
apply_publish_guard_in with the hooks directory this spawn’s env and this host give. Not called under test (see gh_guard::apply_gh_guard), so tests never read the host’s real hooks.
apply_publish_guard_in
Point core.hooksPath at hooks_dir in env, an overlay on process.
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-agent on the path, and with no program run.
gh_agent_hooks_dir
Where gh-agent writes its hooks: GH_AGENT_HOOKS_DIR, else %LOCALAPPDATA%\gh-agent-hooks on Windows and $XDG_DATA_HOME/gh-agent/hooks (default ~/.local/share) elsewhere.
git_config_as_parameters
Hand the GIT_CONFIG_* settings of env (an overlay on process) to the agent as GIT_CONFIG_PARAMETERS instead of GIT_CONFIG_COUNT/_KEY_<n>/_VALUE_<n>.
git_config_entries
The variables that set key = value on top of the GIT_CONFIG_* entries get already sees. Every slot that names key (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_* entries get sees name key (matched without case).
git_config_has_value
Whether the GIT_CONFIG_* entries get sees give key exactly value somewhere (the name matched without case).
git_config_prepend
The variables that put key = value before every GIT_CONFIG_* entry get sees, 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 to process for anything it doesn’t set), if gh-agent has 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 dir holds hooks gh-agent wrote.
scan_ready_in
Whether the hooks in dir are gh-agent’s guard, written by a gh-agent that can judge a container’s push.
set_git_config_list
Make key have exactly values, in order, in the GIT_CONFIG_* entries of env (an overlay on process): 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
env without the GIT_CONFIG_* entries for key (matched without case), the others renumbered.
without_hooks_path
env without its core.hooksPath entries, the others renumbered: for a container, where the host’s hooks directory means nothing, but any other GIT_CONFIG_* setting the agent’s env carries must still work.