hookd

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2026 License: 0BSD Imports: 17 Imported by: 0

Documentation

Overview

Package hookd is the unix-socket bridge between git hooks and the daemon. The hook process (gitbayd in hook mode) computes git facts — it inherits git's quarantine environment, which the daemon does not see — and sends them here; the daemon answers with a policy decision.

pre-receive is two-phase when the repo requires signed commits: the first response sets NeedCommits, and the hook answers with the raw commit objects (only the hook can read them out of quarantine) for verification.

Index

Constants

View Source
const (
	EnvSocket = "GITBAY_HOOK_SOCKET"
	EnvRepoID = "GITBAY_REPO_ID"
	EnvUserID = "GITBAY_USER_ID"
)

Env variable names passed to git transport subprocesses and inherited by hooks.

Variables

This section is empty.

Functions

func Serve

func Serve(cfg config.Config, st *store.Store) (func() error, error)

Serve listens on the unix socket until the listener is closed.

func SocketPath

func SocketPath(root string) string

SocketPath returns the hook socket location. It prefers the server root, but unix socket paths are capped (~104 bytes on macOS, 108 on Linux), so deep roots fall back to a hashed name under the system temp directory. Hooks receive the chosen path via GITBAY_HOOK_SOCKET, so both sides always agree.

func WriteHookScripts

func WriteHookScripts(hooksDir, gitbaydPath string) error

WriteHookScripts (re)generates the shared hooks directory. Called at daemon startup so a moved binary self-heals; every repo points here via core.hooksPath.

Types

type CommitsPayload

type CommitsPayload struct {
	Commits []RawCommit `json:"commits"`
}

CommitsPayload is the hook's second message when NeedCommits was set.

type RawCommit

type RawCommit struct {
	SHA string `json:"sha"`
	Raw []byte `json:"raw"`
}

type Request

type Request struct {
	Hook    string             `json:"hook"` // pre-receive | post-receive
	RepoID  int64              `json:"repo_id"`
	UserID  int64              `json:"user_id"`
	Updates []policy.RefUpdate `json:"updates"`
}

type Response

type Response struct {
	Allow       bool   `json:"allow"`
	Message     string `json:"message,omitempty"`
	NeedCommits bool   `json:"need_commits,omitempty"`
}

func Ask

func Ask(socketPath string, req Request, commits func() (CommitsPayload, error)) (Response, error)

Ask sends one request from the hook process to the daemon. commits is called if the daemon asks for the incoming commit objects.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Source Files

  • hookd.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL