hookd

package
v1.13.3 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 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 RawCommit

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

RawCommit is one incoming commit object. When NeedCommits is set the hook streams these one per JSON value and ends with a zero one, rather than sending a single message holding every commit in the push: an initial push of a large history is tens of thousands of them (#100).

func (RawCommit) Done added in v1.12.0

func (c RawCommit) Done() bool

Done marks the end of the commit stream.

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, stream func(emit func(RawCommit) error) error) (Response, error)

Ask sends one request from the hook process to the daemon. stream is called if the daemon asks for the incoming commit objects; it hands each commit to the callback, which writes it on the wire.

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