Skip to main content

install_git_hooks

Function install_git_hooks 

Source
pub fn install_git_hooks(
    worktree: &Path,
    broker_url: &str,
    agent_id: &str,
) -> Result<(), PawError>
Expand description

Installs git-paw’s post-commit dispatcher and pre-push block hook.

Linked git worktrees share the main repository’s .git/hooks/ directory (unless extensions.worktreeConfig is enabled, which is intrusive). This function therefore:

  1. Resolves the common git dir via git rev-parse --git-common-dir and installs the dispatcher hooks at <common>/hooks/post-commit and <common>/hooks/pre-push (chained onto any existing hooks).
  2. Resolves the linked git dir via git rev-parse --git-dir and writes a per-worktree marker file at <linked>/paw-agent-id containing the PAW_AGENT_ID and PAW_BROKER_URL values the dispatcher will source.

The dispatcher hook reads $GIT_DIR/paw-agent-id at commit time — git sets GIT_DIR to the correct per-worktree gitdir, so each worktree publishes under its own agent id.