hooks

package
v1.234.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package hooks implements Atmos-managed Git hook shims: writing shim scripts into .git/hooks that delegate to `atmos git hooks run`, removing them, and executing the configured command for a named hook.

Index

Constants

View Source
const (
	// ArgsEnvVar holds the arguments Git passed to the hook, joined by single spaces. Shell steps
	// also receive them as positional parameters ($1, "$@"), which keeps arguments with spaces intact.
	ArgsEnvVar = "ATMOS_GIT_HOOK_ARGS"

	// StdinEnvVar holds the path of a file with the data Git piped to the hook on standard input.
	// It is set only for the hooks Git writes data to, for example the refs a pre-push hook is
	// about to update. The file is removed when the hook ends.
	StdinEnvVar = "ATMOS_GIT_HOOK_STDIN"
)
View Source
const (
	// ShimMarker is the unique string embedded in generated shim files.
	// Its presence identifies a file as Atmos-managed.
	ShimMarker = "# Generated by Atmos. Do not edit."
)

Variables

This section is empty.

Functions

func Install

func Install(ctx context.Context, cfg *schema.GitConfig, names []string, force bool) error

Install writes configured hook shims, preserving custom hooks unless force is set. Forced replacement backs up recognized pre-commit framework hooks first.

func IsKnownGitHookName

func IsKnownGitHookName(name string) bool

IsKnownGitHookName reports whether Git itself invokes a hook with this name.

func NotConfiguredError

func NotConfiguredError(hookName string, hooks map[string]schema.GitHookEntry) error

NotConfiguredError builds an ErrGitHookNotConfigured error with a hint listing configured hook names.

func Run

func Run(cfg *schema.GitConfig, hookName string, hookArgs []string, opts ...RunOption) error

Run executes the configured command for the named hook, forwarding the hook arguments and stdin.

func ShimContent

func ShimContent(hookName string) string

ShimContent returns a shim that prefers the current worktree's build and falls back to PATH.

func ShimContentFor

func ShimContentFor(hookName, atmosPath string) string

ShimContentFor returns a shim that resolves the current worktree's build at runtime. Development builds are never pinned into the shared hooks directory. Other installations retain their absolute path as the fallback for GUI clients whose PATH omits atmos.

func SortedNames

func SortedNames(m map[string]schema.GitHookEntry) []string

SortedNames returns the configured hook names in ascending order.

func Uninstall

func Uninstall(ctx context.Context, cfg *schema.GitConfig, names []string) error

Uninstall removes Atmos-generated shims from .git/hooks. With names, only those hooks are removed; without names, every Atmos shim in the hooks directory is removed, including orphans whose hook is no longer configured (they would otherwise fail every Git operation with "git hook not configured"). User-authored hooks are never deleted; a warning is emitted instead.

func ValidateHook

func ValidateHook(name string, entry schema.GitHookEntry) error

ValidateHook checks a hook's configuration without running it: the command-vs-steps exclusivity rule and, for step hooks, the same validation RunSteps performs before executing. Every error carries the hook name.

func ValidateShimName

func ValidateShimName(hookName string) error

ValidateShimName rejects hook names that could escape .git/hooks.

Types

type RunOption

type RunOption func(*runOptions)

RunOption configures a Git hook invocation.

func WithAtmosConfig

func WithAtmosConfig(config *schema.AtmosConfiguration) RunOption

WithAtmosConfig supplies project configuration to step handlers.

func WithContext

func WithContext(ctx context.Context) RunOption

WithContext supplies cancellation and deadlines for step execution.

func WithOutputWriters

func WithOutputWriters(stdout, stderr io.Writer) RunOption

WithOutputWriters routes step output to the host streams.

func WithStdin

func WithStdin(stdin io.Reader) RunOption

WithStdin supplies the data Git pipes to the hook, instead of reading the process's standard input. It applies to the hooks Git writes data to: pre-push, pre-receive, post-receive, post-rewrite, reference-transaction, and proc-receive.

Jump to

Keyboard shortcuts

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