Skip to main content

Module git_hooks

Module git_hooks 

Source
Expand description

What runs around an agent’s git commit and git push when its GitHub access goes through AgentMux.

  • git-hook <name>: the two hooks srv installs for the agent (pre-push, prepare-commit-msg). Each runs the repository’s own hook of the same name first, so a repository’s husky or pre-commit setup keeps working, then does AgentMux’s part: the push scan (secret_scan.rs), the Agent: and Co-authored-by: trailers.
  • git-env -- <git args>: asked by the git shell function before a push or a command that makes commits. It refuses what would skip the hooks (git push --no-verify, a -c core.hooksPath of its own) and prints the environment a commit needs: the App’s bot as author and committer, and who the agent works for, for the trailer.

Enums§

Plan
What git <args> needs from AgentMux.

Constants§

AGENTMUX_HOOKS_DIR
What srv calls its hooks directory (identity/github_hooks.rs).
COMMIT_COMMANDS 🔒
Subcommands that create commits under the agent’s name.
GIT_HOST_ENV
The machine AgentMux runs on, for the commit trailer’s agent@host (set by srv with the git setup).
OWNER_ID_ENV 🔒
Who the agent works for, for the commit trailer (set by git-env, read by the hook).
OWNER_LOGIN_ENV 🔒

Functions§

commit_env
The environment a commit made for granted needs: the App’s bot as author and committer when srv said who the bot is, and the owner for the trailer when it said who the agent works for. Each is on its own: a token without the bot’s user id still carries the owner’s credit.
configured_hooks_dir 🔒
The hooks directory the person or the repository configured: core.hooksPath from the repository (husky), else the person’s global or system configuration. One git config call lists every scope; the environment’s own value (command scope: AgentMux’s directory, set through GIT_CONFIG_*) is not consulted, and an AgentMux directory found in a file is passed over.
forward_to_repo_hook 🔒
Any other hook: the repository’s own, with git’s arguments and standard input as they came. The hooks directory stands in for the repository’s, so each hook the repository has must still run.
git_output 🔒
hooks_dir_from 🔒
The winning core.hooksPath in git config --show-scope --get-regexp output (<scope>\t<key> <value> per line, the lowest-precedence scope first).
is_executable 🔒
Git skips a hook that isn’t executable; so does this.
is_no_verify 🔒
Whether arg is --no-verify, or an abbreviation git accepts for it (--no-verif, --no-v: long options may be shortened while they stay unambiguous).
plan_for
What git <args> is, and whether it may run. Err is what to tell the agent.
pre_push 🔒
pre-push <remote> <url>, the refs on stdin.
prepare_commit_msg 🔒
prepare-commit-msg <file> [source] [sha].
push_diff 🔒
The diff of what pushing local over remote_sha adds, -U0; None when git can’t produce it.
repo_own_hook 🔒
The repository’s own hook name, if it has one: from the configured hooks directory, else .git/hooks.
run_git_env
git-env -- <git args>: refuse, or print KEY=VALUE lines for the shell function to run git with.
run_git_hook
git-hook <name> <git's arguments>.
run_script 🔒
trailers
The trailers a commit of an agent carries: who wrote it, and whose agent that is.