githook

package
v1.105.0-pre Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package githook contains the shared implementation of Tailscale's git hooks. The tailscale/tailscale and tailscale/corp repositories each have a thin main package that dispatches to this one, calling individual hook functions with per-repo arguments as needed.

Index

Constants

This section is empty.

Variables

View Source
var HookVersion string

HookVersion is the shared version of this package and launcher.sh. Bump HOOK_VERSION on any change under this package.

View Source
var Launcher []byte

Launcher is the canonical bytes of launcher.sh. Downstream repos (e.g. tailscale/corp) rely on these bytes at install time.

Functions

func AddChangeID

func AddChangeID(args []string) error

AddChangeID strips comments from the commit message at args[0] and prepends a random Change-Id trailer.

Intended as a commit-msg hook. https://git-scm.com/docs/githooks#_commit_msg

func CheckForbiddenMarkers

func CheckForbiddenMarkers() error

CheckForbiddenMarkers scans the staged diff for forbidden markers and returns an error if any are found.

Intended as a pre-commit hook. https://git-scm.com/docs/githooks#_pre_commit

func CheckPrePush added in v1.104.0

func CheckPrePush(args []string, cfg PrePushConfig) error

CheckPrePush reads pushes from stdin and validates them per cfg. args is the pre-push hook's argv (remoteName, remoteLoc).

Intended as a pre-push hook. https://git-scm.com/docs/githooks#_pre_push

func Install

func Install() error

Install writes the launcher to .git/hooks/ts-git-hook and runs it once with "version", bootstrapping the binary build and per-hook wrappers. Called from each repo's misc/add-git-hooks.go.

func RunLocalHook

func RunLocalHook(hookName string, args []string) error

RunLocalHook runs an optional user-supplied hook at .git/hooks/<name>.local, if present.

func WriteHooks

func WriteHooks(hooks []string) error

WriteHooks writes the launcher to .git/hooks/ts-git-hook and a wrapper for each name in hooks to .git/hooks/<name>. Stale wrappers from prior versions (ours, but no longer in hooks) are removed. If a path we are about to write exists and is not one of our wrappers, WriteHooks aborts with an error rather than clobber the user's hook. Called by the binary's "install" handler (after a rebuild) and by Install (initial setup).

Types

type PrePushConfig added in v1.104.0

type PrePushConfig struct {
	// WatchedRemotes are the remote URLs whose pushes are subject to
	// the go.mod replace check.
	WatchedRemotes []string

	// AllowedReplaceDirs are the directory-path go.mod replace targets
	// that are permitted in pushed commits.
	AllowedReplaceDirs []string

	// MaxBlobSize, if positive, is the largest new or changed blob in
	// bytes allowed in a push to any remote. Pushes adding larger
	// blobs are rejected unless the TS_SKIP_LARGE_FILE_CHECK
	// environment variable is set to a non-empty value.
	MaxBlobSize int64
}

PrePushConfig configures CheckPrePush.

Jump to

Keyboard shortcuts

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